<?php

namespace App\Domain\Accounting\Enums;

/** The six groups of the chart of accounts (§33). */
enum AccountType: string
{
    case Asset = 'asset';
    case Liability = 'liability';
    case Equity = 'equity';
    case Revenue = 'revenue';
    case CostOfService = 'cost_of_service';
    case Expense = 'expense';

    public function label(): string
    {
        return match ($this) {
            self::Asset => 'Assets',
            self::Liability => 'Liabilities',
            self::Equity => 'Equity',
            self::Revenue => 'Revenue',
            self::CostOfService => 'Cost of Services',
            self::Expense => 'Operating Expenses',
        };
    }

    /** The side that increases this account. */
    public function normalBalance(): string
    {
        return match ($this) {
            self::Asset, self::CostOfService, self::Expense => 'debit',
            self::Liability, self::Equity, self::Revenue => 'credit',
        };
    }

    /** Balance sheet accounts carry forward; the rest close into equity. */
    public function isBalanceSheet(): bool
    {
        return in_array($this, [self::Asset, self::Liability, self::Equity], true);
    }

    /** @return array<int, string> */
    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }
}
