<?php
declare(strict_types=1);

namespace App\Modules\Accounting\Models;

use App\Core\Model;

class BankAccount extends Model
{
    protected static string $table = 'bank_accounts';
    protected static array $fillable = [
        'account_name_ar', 'account_name_en', 'bank_name_ar', 'bank_name_en',
        'account_number', 'iban', 'swift_code', 'branch_name', 'currency',
        'gl_account_id', 'opening_balance', 'current_balance',
        'is_default', 'is_active', 'notes',
    ];
    protected static bool $timestamps = true;
    protected static bool $softDelete = true;

    public static function getDefault(): ?static
    {
        $row = static::query()
            ->where('is_default', '=', 1)
            ->where('is_active', '=', 1)
            ->where('is_archived', '=', 0)
            ->first();
        if ($row === null) {
            return null;
        }
        $instance = new static($row);
        $instance->exists = true;
        return $instance;
    }

    public static function getActive(): array
    {
        return static::query()
            ->where('is_active', '=', 1)
            ->where('is_archived', '=', 0)
            ->orderBy('account_name_ar', 'ASC')
            ->get();
    }
}
