<?php

declare(strict_types=1);

namespace Kylin\Agriculture\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Kylin\Agriculture\Enums\MaterialLogType;

/**
 * 物料模型
 *
 * 管理农业物料（种子、化肥、农药等）的库存信息。
 *
 * @property string $name     物料名称
 * @property string $unit     单位
 * @property float  $quantity 库存数量
 */
class Material extends Model
{
    protected $table = 'kylin_agri_materials';

    protected $fillable = [
        'name',
        'category',
        'unit',
        'stock',
        'safety_stock',
        'price',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'stock' => 'decimal:2',
            'safety_stock' => 'decimal:2',
            'price' => 'decimal:2',
            'status' => 'boolean',
        ];
    }

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