<?php

namespace App\Modules\Sales\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 SalesOrderLine extends Model
{
    use BelongsToTenant;

    protected $table = 'sales_order_lines';

    protected $fillable = [
        'tenant_id',
        'sales_order_id',
        'line_position',
        'warehouse_id',
        'item_id',
        'quantity_ordered',
        'quantity_reserved',
        'quantity_fulfilled',
        'reservation_public_id',
    ];

    public function salesOrder(): BelongsTo
    {
        return $this->belongsTo(SalesOrder::class, 'sales_order_id');
    }

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

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