<?php

namespace App\Modules\Inventory\Stock\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use App\Modules\Inventory\Models\Item;
use App\Modules\Inventory\Models\Warehouse;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class InventoryStockProjection extends Model
{
    use BelongsToTenant;

    protected $table = 'inventory_stock_projections';

    protected $fillable = [
        'tenant_id',
        'warehouse_id',
        'item_id',
        'on_hand_quantity',
        'reserved_quantity',
        'available_quantity',
        'row_version',
        'last_movement_id',
        'last_rebuilt_at',
    ];

    protected function casts(): array
    {
        return [
            'on_hand_quantity' => 'decimal:8',
            'reserved_quantity' => 'decimal:8',
            'available_quantity' => 'decimal:8',
            'last_rebuilt_at' => 'datetime',
        ];
    }

    public function warehouse(): BelongsTo
    {
        return $this->belongsTo(Warehouse::class, 'warehouse_id');
    }

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