<?php

namespace App\Models\Tenants;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class AccountCode extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'code',
        'name',
        'category',
        'sort_order',
        'is_active',
    ];

    protected $casts = [
        'sort_order' => 'integer',
        'is_active' => 'boolean',
    ];

    // Categories
    public const CATEGORY_ASSET = 'asset';
    public const CATEGORY_LIABILITY = 'liability';
    public const CATEGORY_CAPITAL = 'capital';
    public const CATEGORY_REVENUE = 'revenue';
    public const CATEGORY_EXPENSE = 'expense';

    public const CATEGORIES = [
        self::CATEGORY_ASSET => '자산',
        self::CATEGORY_LIABILITY => '부채',
        self::CATEGORY_CAPITAL => '자본',
        self::CATEGORY_REVENUE => '수익',
        self::CATEGORY_EXPENSE => '비용',
    ];

    /**
     * 활성 계정과목만 조회
     */
    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }
}
