<?php

namespace App\Models;

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

class CreditsDeductable extends Model
{
    use HasFactory;

    protected $table = 'credits_deductables';

    protected $fillable = [
        'client_id',
        'request_date',
        'requested_amount',
        'purpose',
        'status',
        'disbursement_date',
        'repayment_term',
        'interest_rate',
        'guarantee_type',
        'comments',
        'service_charges',
        'mandatory_savings',
        'total_deductions',
        'total_loan_cost',
        'total_repayable',
        'cash_to_client',
        'order_id',
        'seed_id', // Keep this since you have the column
        'createdby'
    ];

    // Relationships
    public function client()
    {
        return $this->belongsTo(Client::class, 'client_id');
    }

    public function order()
    {
        return $this->belongsTo(Order::class, 'order_id');
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'createdby');
    }

    // Update this relationship to use the correct model
    public function seed()
    {
        return $this->belongsTo(InputsActivitiesCostsSeed::class, 'seed_id');
    }
    public function creditRequest()
{
    return $this->belongsTo(CreditRequest::class, 'client_id', 'client_id');
}
public function CommitteeApproval()
{
    return $this->hasOne(CommitteeApproval::class, 'client_id', 'client_id');
}

}