<?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 InventoryUnitConversion extends Model
{
    use BelongsToTenant;

    protected $table = 'inventory_unit_conversions';

    protected $fillable = [
        'tenant_id',
        'from_unit_id',
        'to_unit_id',
        'factor',
        'is_active',
    ];

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

    public function fromUnit(): BelongsTo
    {
        return $this->belongsTo(InventoryUnit::class, 'from_unit_id');
    }

    public function toUnit(): BelongsTo
    {
        return $this->belongsTo(InventoryUnit::class, 'to_unit_id');
    }
}
