<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class FinancialAccount extends Model
{
    public const TYPES = ['cash','mobile_money','bank','petty_cash','safe','collection','other'];
    public const STATUSES = ['active','inactive'];

    protected $fillable = ['branch_id','name','account_type','opening_balance','current_balance','status','reference_details','created_by','updated_by'];

    protected function casts(): array
    {
        return ['opening_balance'=>'decimal:2','current_balance'=>'decimal:2'];
    }

    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
    public function transactions(): HasMany { return $this->hasMany(FinancialAccountTransaction::class, 'account_id')->orderByDesc('id'); }
}
