<?php

namespace App\Domains\Catalog\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

#[Fillable([
    'bundle_catalog_item_id',
    'component_catalog_item_id',
    'component_variant_id',
    'quantity',
])]
class BundleComponent extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected function casts(): array
    {
        return [
            'bundle_catalog_item_id' => 'integer',
            'component_catalog_item_id' => 'integer',
            'component_variant_id' => 'integer',
            'quantity' => 'integer',
        ];
    }

    /** @return BelongsTo<CatalogItem, $this> */
    public function bundle(): BelongsTo
    {
        return $this->belongsTo(CatalogItem::class, 'bundle_catalog_item_id');
    }

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

    /** @return BelongsTo<Variant, $this> */
    public function variant(): BelongsTo
    {
        return $this->belongsTo(Variant::class, 'component_variant_id');
    }
}
