<?php

namespace App\Models;

use App\Enums\AccountCategory;
use App\Enums\AccountStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Account extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'code',
        'name',
        'category',
        'account_type',
        'normal_balance_side',
        'opening_balance',
        'opening_balance_date',
        'status',
        'description',
    ];

    protected function casts(): array
    {
        return [
            'category' => AccountCategory::class,
            'status' => AccountStatus::class,
            'opening_balance' => 'decimal:2',
            'opening_balance_date' => 'date',
        ];
    }

    public function journalLines(): HasMany
    {
        return $this->hasMany(JournalLine::class);
    }

    public function expenses(): HasMany
    {
        return $this->hasMany(Expense::class);
    }

    public function invoiceLines(): HasMany
    {
        return $this->hasMany(InvoiceLine::class);
    }

    public function receipts(): HasMany
    {
        return $this->hasMany(Receipt::class);
    }

    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class);
    }

    public function budgetLines(): HasMany
    {
        return $this->hasMany(BudgetLine::class);
    }

    public function bankReconciliations(): HasMany
    {
        return $this->hasMany(BankReconciliation::class);
    }

    public function fixedAssetsAsAssetAccount(): HasMany
    {
        return $this->hasMany(FixedAsset::class, 'asset_account_id');
    }

    public function fixedAssetsAsDepreciationAccount(): HasMany
    {
        return $this->hasMany(FixedAsset::class, 'depreciation_account_id');
    }
}
