<?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\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;

final class ManualJournalVoucher extends Model
{
    use HasPublicId, ImmutableWhenPosted;
    protected $fillable=['public_id','company_id','branch_id','voucher_number','posting_date','document_date','reference_number','description','currency_code','exchange_rate','debit_total','credit_total','status','approved_by','approved_at','posted_at','created_by'];
    protected function casts():array{return['posting_date'=>'date','document_date'=>'date','exchange_rate'=>'decimal:8','debit_total'=>'decimal:4','credit_total'=>'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 lines():HasMany{return $this->hasMany(ManualJournalLine::class);}public function journal():MorphOne{return $this->morphOne(JournalEntry::class,'source');}
}
