<?php
declare(strict_types=1);

namespace App\Modules\Inventory\Models;

use App\Core\Model;
use App\Core\App;

class StockTransferItem extends Model
{
    protected static string $table = 'stock_transfer_items';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = false;
    protected static bool $softDelete = false;
    protected static bool $autoTrackAuthor = false;

    protected static array $fillable = [
        'transfer_id',
        'item_id',
        'quantity',
        'batch_id',
        'notes',
    ];

    /**
     * Get all items for a transfer with item details.
     */
    public static function getForTransfer(int $transferId): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT sti.*, i.`name_ar` as item_name, i.`sku`, i.`unit_of_measure`
             FROM `stock_transfer_items` sti
             JOIN `inventory_items` i ON i.`id` = sti.`item_id`
             WHERE sti.`transfer_id` = ?
             ORDER BY i.`name_ar` ASC",
            [$transferId]
        );
    }
}
