<?php

namespace App\Modules\Inventory\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ItemAttributeValue extends Model
{
    use BelongsToTenant;

    protected $table = 'inventory_item_attribute_values';

    protected $fillable = [
        'tenant_id',
        'item_id',
        'attribute_id',
        'value_text',
        'value_textarea',
        'value_number',
        'value_boolean',
        'value_date',
        'value_json',
    ];

    protected function casts(): array
    {
        return [
            'value_boolean' => 'boolean',
            'value_date' => 'date',
            'value_number' => 'decimal:8',
            'value_json' => 'array',
        ];
    }

    public function item(): BelongsTo
    {
        return $this->belongsTo(Item::class, 'item_id');
    }

    public function attribute(): BelongsTo
    {
        return $this->belongsTo(InventoryAttribute::class, 'attribute_id');
    }
}
