<?php

declare(strict_types=1);

namespace Kylin\Agriculture\Models;

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

/**
 * 产量记录模型
 *
 * 记录农作物产量数据。
 *
 * @property string $crop     作物名称
 * @property float  $quantity 产量
 * @property string $unit     单位
 */
class YieldRecord extends Model
{
    protected $table = 'kylin_agri_yield_records';

    protected $fillable = [
        'plot_id',
        'planting_plan_id',
        'crop',
        'quantity',
        'unit',
        'cost',
        'revenue',
        'recorded_at',
    ];

    protected function casts(): array
    {
        return [
            'quantity' => 'decimal:2',
            'cost' => 'decimal:2',
            'revenue' => 'decimal:2',
            'recorded_at' => 'datetime',
        ];
    }

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

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