<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;

class Treatment extends Model
{
    /** @use HasFactory<\Database\Factories\TreatmentFactory> */
    use HasFactory;

    protected $primaryKey = 'treatment_id';
    
    protected $fillable = [
        'row_id',
        'note',
    ];

    /**
     * Get the vineyard row that has this treatment.
     */
    public function vineyardRow(): BelongsTo
    {
        return $this->belongsTo(VineyardRow::class, 'row_id');
    }

    /**
     * Get the planned task associated with this treatment.
     */
    public function plannedTask(): MorphOne
    {
        return $this->morphOne(PlannedTask::class, 'taskable');
    }
}
