<?php

namespace App\Models;

use App\Filters\HarvestFilters;
use Essa\APIToolKit\Filters\Filterable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Harvest extends Model
{
    use HasFactory, SoftDeletes, Filterable;

    protected string $default_filters = HarvestFilters::class;

    protected $table = "harvest_headers";

    protected $fillable = [
        "harvest_date",
        "harvest_time",
        "buyer_type",
        "buyer",
        "plate_no",
        "building_id",
        "building_name",
        "farm_id",
        "farm_code",
        "farm_name",
        "batch_id",
        "batch_code",
        "lead_man_id",
        "lead_man_name",
        "population_before_harvest",
        "remaining",
        "total_harvest",
        "total_weight",
        "created_by",
        "status",
        "synced_status",
        "synced_at",
        "synced_id",
        "attachment_path",
        "attachment_uploaded_at"
    ];

    protected $casts = [
        "harvest_date" => "date",
        'harvest_time' => 'datetime:H:i:s',
        "population_before_harvest" => "integer",
    ];

    public function batch()
    {
        return $this->belongsTo(Batches::class, "batch_id", "id");
    }

    public function lines()
    {
        return $this->hasMany(HarvestLines::class, "harvest_id", "id");
    }
}
