<?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 App\Modules\Inventory\Stock\Support\InventoryStockTransferStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class InventoryStockTransfer extends Model
{
    use BelongsToTenant;

    protected $table = 'inventory_stock_transfers';

    protected $fillable = [
        'tenant_id',
        'status',
        'transfer_number',
        'source_warehouse_id',
        'destination_warehouse_id',
        'item_id',
        'quantity',
        'correlation_id',
        'transfer_out_movement_id',
        'transfer_in_movement_id',
        'completed_at',
    ];

    protected function casts(): array
    {
        return [
            'quantity' => 'decimal:8',
            'correlation_id' => 'string',
            'completed_at' => 'datetime',
            'status' => InventoryStockTransferStatus::class,
        ];
    }

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

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

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