<?php

namespace Kylin\Catering\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 菜品
 */
class Dish extends Model
{
    protected $table = 'catering_dishes';
    protected $fillable = [
        'category_id',
        'name',
        'price',
        'cost',
        'description',
        'image_url',
        'unit',
        'specifications',
        'allergens',
        'is_on_sale',
        'sort_order',
    ];

    protected $casts = [
        'category_id' => 'integer',
        'price' => 'decimal:2',
        'cost' => 'decimal:2',
        'specifications' => 'array',
        'allergens' => 'array',
        'is_on_sale' => 'boolean',
        'sort_order' => 'integer',
    ];

    public function category(): BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

    public function orderItems(): HasMany
    {
        return $this->hasMany(OrderItem::class);
    }
}
