<?php

namespace App\Models;

use App\Enums\ChargeBasis;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PackageItem extends Model
{
    /**
     * @var list<string>
     */
    protected $fillable = [
        'package_id',
        'product_id',
        'description_override',
        'default_quantity',
        'charge_basis_override',
        'price_override',
        'is_mandatory',
        'is_optional',
        'is_complimentary',
        'sort_order',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'default_quantity' => 'decimal:2',
            'charge_basis_override' => ChargeBasis::class,
            'price_override' => 'decimal:2',
            'is_mandatory' => 'boolean',
            'is_optional' => 'boolean',
            'is_complimentary' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    /**
     * @return BelongsTo<Package, $this>
     */
    public function package(): BelongsTo
    {
        return $this->belongsTo(Package::class);
    }

    /**
     * @return BelongsTo<Product, $this>
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class);
    }
}
