<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;

class GiftItem extends Model
{
    public const TYPE_INCLUDED = 'included';
    public const TYPE_ADDITIONAL = 'additional';

    protected $fillable = [
        'organization_id',
        'mariachi_group_id',
        'code',
        'name',
        'type',
        'internal_cost',
        'base_price',
        'is_active',
        'is_default',
        'sort_order',
    ];

    protected $casts = [
        'organization_id' => 'integer',
        'mariachi_group_id' => 'integer',
        'internal_cost' => 'float',
        'base_price' => 'float',
        'is_active' => 'boolean',
        'is_default' => 'boolean',
        'sort_order' => 'integer',
    ];

    public static function defaultCatalog(): array
    {
        return [
            ['code' => 'rose', 'name' => 'Rosa', 'type' => self::TYPE_INCLUDED, 'base_price' => 10000, 'sort_order' => 10],
            ['code' => 'balloon', 'name' => 'Globo', 'type' => self::TYPE_INCLUDED, 'base_price' => 12000, 'sort_order' => 20],
            ['code' => 'chocolate', 'name' => 'Chocolates', 'type' => self::TYPE_INCLUDED, 'base_price' => 18000, 'sort_order' => 30],
            ['code' => 'wine', 'name' => 'Botella de vino', 'type' => self::TYPE_ADDITIONAL, 'base_price' => 45000, 'sort_order' => 40],
            ['code' => 'cake', 'name' => 'Mini torta', 'type' => self::TYPE_ADDITIONAL, 'base_price' => 35000, 'sort_order' => 50],
        ];
    }

    public function priceRules(): MorphMany
    {
        return $this->morphMany(CatalogPriceRule::class, 'priceable');
    }

    public function mariachiGroup()
    {
        return $this->belongsTo(MariachiGroup::class);
    }
}
