<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\Offers\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Maestro\Core\Modules\Offers\Enums\OfferDiscountType;
use Maestro\Core\Modules\Offers\Enums\OfferPricingType;

class OfferRow extends Model
{
    protected $table = 'offer_rows';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'offer_section_id',
        'offer_service_catalog_item_id',
        'description_html',
        'pricing_type',
        'custom_unit_label',
        'quantity',
        'unit_price',
        'discount_type',
        'discount_value',
        'vat_rate',
        'sort_order',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'pricing_type' => OfferPricingType::class,
            'discount_type' => OfferDiscountType::class,
        ];
    }

    /**
     * @return BelongsTo<OfferSection, OfferRow>
     */
    public function section(): BelongsTo
    {
        return $this->belongsTo(OfferSection::class, 'offer_section_id');
    }

    /**
     * @return BelongsTo<OfferServiceCatalogItem, OfferRow>
     */
    public function catalogItem(): BelongsTo
    {
        return $this->belongsTo(OfferServiceCatalogItem::class, 'offer_service_catalog_item_id');
    }
}
