<?php
declare(strict_types=1);

namespace App\Modules\Accounting\Models;

use App\Core\Model;
use App\Core\App;

class AccountingDimension extends Model
{
    protected static string $table = 'accounting_dimensions';
    protected static array $fillable = [
        'code', 'name_ar', 'name_en', 'is_required', 'is_active',
    ];
    protected static bool $timestamps = true;
    protected static bool $softDelete = false;

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

    public function getValues(): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT * FROM accounting_dimension_values WHERE dimension_id = ? AND is_active = 1 ORDER BY code",
            [(int)$this->id]
        );
    }

    public static function getValuesForDimension(int $dimensionId): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT * FROM accounting_dimension_values WHERE dimension_id = ? AND is_active = 1 ORDER BY code",
            [$dimensionId]
        );
    }
}
