<?php
namespace App\Models;

use App\Enums\AccountType;
use App\Enums\NormalBalance;
use App\Models\Concerns\HasPublicId;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

final class Account extends Model
{
    use HasPublicId;


protected $fillable = ['public_id','company_id','parent_id','code','name','type','normal_balance','is_control_account','is_active','system_key'];
protected function casts(): array { return ['type'=>AccountType::class,'normal_balance'=>NormalBalance::class,'is_control_account'=>'boolean','is_active'=>'boolean']; }
public function company(): BelongsTo { return $this->belongsTo(Company::class); }
public function parent(): BelongsTo { return $this->belongsTo(Account::class, 'parent_id'); }
public function children(): HasMany { return $this->hasMany(Account::class, 'parent_id'); }
}
