<?php
declare(strict_types=1);

namespace App\Modules\Procurement\Models;

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

class RtvItem extends Model
{
    protected static string $table = 'rtv_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 = [
        'rtv_id', 'item_id', 'grn_item_id', 'quantity', 'unit_cost',
        'line_total', 'batch_number', 'reason',
    ];

    public static function getForRTV(int $rtvId): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT ri.*, i.`name_ar` as item_name, i.`sku`
             FROM `rtv_items` ri
             JOIN `inventory_items` i ON i.`id` = ri.`item_id`
             WHERE ri.`rtv_id` = ?
             ORDER BY ri.`id` ASC",
            [$rtvId]
        );
    }
}
