<?php

namespace App\Models;

use App\Enums\PackagePricingMethod;
use App\Enums\PackageStatus;
use App\Enums\PackageType;
use Database\Factories\PackageFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Package extends Model
{
    /** @use HasFactory<PackageFactory> */
    use HasFactory, SoftDeletes;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'code',
        'category',
        'package_type',
        'description',
        'event_types',
        'min_guests',
        'max_guests',
        'valid_from',
        'valid_to',
        'status',
        'image_path',
        'default_terms',
        'pricing_method',
        'fixed_price',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'event_types' => 'array',
            'min_guests' => 'integer',
            'max_guests' => 'integer',
            'valid_from' => 'date',
            'valid_to' => 'date',
            'status' => PackageStatus::class,
            'package_type' => PackageType::class,
            'pricing_method' => PackagePricingMethod::class,
            'fixed_price' => 'decimal:2',
        ];
    }

    /**
     * @return HasMany<PackageItem, $this>
     */
    public function items(): HasMany
    {
        return $this->hasMany(PackageItem::class)->orderBy('sort_order');
    }
}
