<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class TenderEntry extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'tender_entry';
    protected $primaryKey = 'TE_Id';

    protected $fillable = [
        'Dpt_id',
        'Lg_Id',
        'Bh_Id',
        'TnT_ID',
        'Proposal_Amount',
        'Approved_Amount',
        'Acc_Chl_No',

        // 🔥 Updated fields
        'TE_Date',
        'TE_St_Date',
        'TE_Ed_Date',
        'BG_Per',
        'EMD_Per',
        'TE_Fee',

        'Description',
        'Documents'
    ];

    protected $casts = [
        'Documents'   => 'array',
        'TE_St_Date'  => 'date',
        'TE_Ed_Date'  => 'date',
        'TE_Fee'      => 'decimal:2'
    ];

    // Department
    public function department()
    {
        return $this->belongsTo(Department::class, 'Dpt_id', 'Dpt_id');
    }

    // Ledger
    public function ledger()
    {
        return $this->belongsTo(LedgerMaster::class, 'Lg_Id', 'Lg_Id');
    }

    // Budget Head
    public function budgetHead()
    {
        return $this->belongsTo(BudgetHead::class, 'Bh_Id', 'Bh_Id');
    }

    // Tender Type
    public function tendertype()
    {
        return $this->belongsTo(TenderType::class, 'TnT_ID', 'TnT_ID');
    }
}
