<?php

namespace App\Models;

use App\Enums\MealType;
use Database\Factories\RecipeFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;

/**
 * @property int $id
 * @property string $name
 * @property string|null $description
 * @property string $instructions
 * @property int $prep_time
 * @property int $cook_time
 * @property int $servings
 * @property string|null $image_url
 * @property MealType $meal_type
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 */
#[Fillable(['name', 'description', 'instructions', 'prep_time', 'cook_time', 'servings', 'image_url', 'meal_type'])]
class Recipe extends Model
{
    /** @use HasFactory<RecipeFactory> */
    use HasFactory;

    protected function casts(): array
    {
        return [
            'prep_time' => 'integer',
            'cook_time' => 'integer',
            'servings' => 'integer',
            'meal_type' => MealType::class,
        ];
    }

    /**
     * @return HasMany<RecipeIngredient, $this>
     */
    public function ingredients(): HasMany
    {
        return $this->hasMany(RecipeIngredient::class);
    }
}
