<?php

namespace App\Modules\Inventory\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\Inventory\Support\InventoryUserStamp;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class InventoryUnit extends Model
{
    use BelongsToTenant;
    use InventoryUserStamp;

    protected $table = 'inventory_units';

    protected $fillable = [
        'tenant_id',
        'code',
        'name',
        'symbol',
        'is_base',
        'is_active',
        'created_by',
        'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'is_base' => 'boolean',
            'is_active' => 'boolean',
        ];
    }

    public function conversionsFrom(): HasMany
    {
        return $this->hasMany(InventoryUnitConversion::class, 'from_unit_id');
    }

    public function conversionsTo(): HasMany
    {
        return $this->hasMany(InventoryUnitConversion::class, 'to_unit_id');
    }
}
