<?php

namespace App\Models;

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

class TreatmentLog extends Model
{
    protected $fillable = [
        'pond_id', 'cycle_id', 'treatment_date', 'drug_chemical_name', 'dosage',
        'application_method', 'duration_days', 'withdrawal_period_days',
        'harvest_safe_after', 'cost_naira', 'administered_by', 'outcome',
        'notes', 'logged_by',
    ];

    protected function casts(): array
    {
        return [
            'treatment_date' => 'date',
            'harvest_safe_after' => 'date',
            'cost_naira' => 'decimal:2',
        ];
    }

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

    public function cycle(): BelongsTo
    {
        return $this->belongsTo(ProductionCycle::class, 'cycle_id');
    }

    public function logger(): BelongsTo
    {
        return $this->belongsTo(User::class, 'logged_by');
    }

    public function isWithdrawalActive(): bool
    {
        return $this->harvest_safe_after && $this->harvest_safe_after->isFuture();
    }
}
