<?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;

/**
 * 病虫害记录模型
 *
 * 记录农作物病虫害发生情况。
 *
 * @property string $pest_type   病虫害类型
 * @property string $description 描述
 * @property string $severity    严重程度
 */
class PestRecord extends Model
{
    protected $table = 'kylin_agri_pest_records';

    protected $fillable = [
        'plot_id',
        'pest_type',
        'description',
        'images',
        'severity',
        'recorder_id',
        'recorded_at',
    ];

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

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

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

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