<?php

namespace App\Models;

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

class CommitteeApproval extends Model
{
    use HasFactory;

    protected $table = 'creditcommittee_approvals';

    protected $fillable = [
        'client_id',
        'seed_id',
        'approved_amount',
        'description',
        'comments',
        'service_charges',
        'mandatory_savings',
        'total_deductions',
        'total_loan_cost',
        'cash_to_client',
        'total_repayable',
        'original_agent_proposal',
        'client_original_request',
        'payedAmount',
        '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');
}

    
    // If you want to link the credit requested by this client for this seed
    public function credit()
    {
        return $this->belongsTo(Credit::class, 'client_id', 'client_id')
                    ->where('seed_id', $this->seed_id);
    }

     public function CreditDeductable()
    {
        return $this->hasOne(CreditDeductable::class, 'client_id', 'client_id');
    }
}
