<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SupplierDocumentLine extends Model
{
    protected $fillable = [
        'supplier_document_header_id',
        'module', 'hs_code', 'item_id', 'account_id', 'warehouse_id',
        'quantity', 'confirmed_quantity', 'uom_id', 'price', 'tax_id',
        'tax_rate', 'discount_percent', 'line_tax', 'line_total', 'description',
        'account_type',
    ];

    public function header(): BelongsTo
    {
        return $this->belongsTo(SupplierDocumentHeader::class, 'supplier_document_header_id');
    }

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

    public function itemWarehouse()
    {
        return $this->hasOne(ItemWarehouse::class, 'item_id', 'item_id')
            ->whereColumn('warehouse_id', 'warehouse_id');
    }

    public function account(): BelongsTo
    {
        return $this->belongsTo(MainAccount::class, 'account_id');
    }

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

    public function tax(): BelongsTo
    {
        return $this->belongsTo(Tax::class);
    }

    public function uom(): BelongsTo
    {
        return $this->belongsTo(Uom::class);
    }

}
