<?php

namespace App\Models;

use App\Enums\DocumentStatus;
use App\Models\Concerns\HasPublicId;
use App\Models\Concerns\ImmutableWhenPosted;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;

final class DriverSettlement extends Model
{
    use HasPublicId, ImmutableWhenPosted;
    protected $fillable=['public_id','company_id','branch_id','driver_advance_id','settlement_number','settlement_date','expense_amount','cash_refund_amount','total_settled','expense_account_id','cash_bank_account_id','description','status','approved_by','approved_at','posted_at','created_by'];
    protected function casts():array{return['settlement_date'=>'date','expense_amount'=>'decimal:4','cash_refund_amount'=>'decimal:4','total_settled'=>'decimal:4','status'=>DocumentStatus::class,'approved_at'=>'datetime','posted_at'=>'datetime'];}
    public function company():BelongsTo{return $this->belongsTo(Company::class);} public function branch():BelongsTo{return $this->belongsTo(Branch::class);} public function advance():BelongsTo{return $this->belongsTo(DriverAdvance::class,'driver_advance_id');} public function expenseAccount():BelongsTo{return $this->belongsTo(Account::class,'expense_account_id');} public function cashBankAccount():BelongsTo{return $this->belongsTo(Account::class,'cash_bank_account_id');} public function journal():MorphOne{return $this->morphOne(JournalEntry::class,'source');}
}
