<?php

declare(strict_types=1);

namespace Kylin\Agriculture\Models;

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

/**
 * 农事记录模型
 *
 * 记录农事操作，如施肥、灌溉、除草等。
 *
 * @property string $type        农事类型
 * @property string $description 操作描述
 * @property string $recorded_at 操作时间
 */
class FarmRecord extends Model
{
    protected $table = 'kylin_agri_farm_records';

    protected $fillable = [
        'plot_id',
        'planting_plan_id',
        'type',
        'content',
        'images',
        'operator_id',
        'recorded_at',
    ];

    protected function casts(): array
    {
        return [
            'type' => FarmRecordType::class,
            'images' => 'array',
            'recorded_at' => 'datetime',
        ];
    }

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

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

    public function operator(): BelongsTo
    {
        return $this->belongsTo(config('auth.providers.users.model'), 'operator_id');
    }
}
