<?php

namespace App\Support;

class SalaryComponentOptions
{
    public static function types(): array
    {
        return [
            'earning'   => 'Earnings',
            'deduction' => 'Deductions',
        ];
    }

    public static function subTypes(string $type): array
    {
        return match ($type) {
            'earning' => [
                'festival_bonus'     => 'Festival Bonus',
                'pf_company_portion' => 'PF-Company Portion',
                'gratuity'           => 'Gratuity',
                'general_earnings'   => 'General Earnings',
            ],
            'deduction' => [
                'tax_deduction'         => 'TAX Deduction',
                'pf_own_deduction'      => 'PF (Own) Deduction',
                'pf_company_deduction'  => 'PF (Company) Deduction',
                'general_deduction'     => 'General Deduction',
            ],
            default => [],
        };
    }

    public static function allSubTypes(): array
    {
        $all = [];
        foreach (array_keys(static::types()) as $type) {
            foreach (static::subTypes($type) as $key => $label) {
                $all[$key] = $label;
            }
        }

        return $all;
    }

    public static function subTypeLabel(?string $type, ?string $subType): string
    {
        if (!$subType) {
            return '—';
        }

        return static::subTypes((string) $type)[$subType] ?? ucwords(str_replace('_', ' ', $subType));
    }

    public static function typeLabel(?string $type): string
    {
        return static::types()[$type] ?? ucfirst((string) $type);
    }
}
