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

class VarietyVariation extends Model
{
    use HasFactory;

    protected $table = 'variety_variations';

    protected $fillable = [
        'grape_variety_id',
        'color',
        'description',
        'typical_sugar_content',
        'typical_alcohol',
        'ripening_period',
        'status',
    ];

    protected $casts = [
        'typical_sugar_content' => 'decimal:2',
        'typical_alcohol' => 'decimal:2',
    ];

    /**
     * Get the grape variety that owns this variation.
     */
    public function grapeVariety(): BelongsTo
    {
        return $this->belongsTo(GrapeVariety::class, 'grape_variety_id');
    }

    /**
     * Get the vineyard rows for this variety variation.
     */
    public function vineyardRows(): HasMany
    {
        return $this->hasMany(VineyardRow::class, 'variety_variation_id');
    }

    /**
     * Get the harvests for this variety variation.
     */
    public function harvests(): HasMany
    {
        return $this->hasMany(Harvest::class, 'variety_variation_id');
    }
}
