<?php

namespace App\Support;

class SalaryComponentAccountQuickAdd
{
    /**
     * @return array<string, array{label: string, type: string}>
     */
    public static function sectionsForListKey(string $listKey): array
    {
        $keys = match ($listKey) {
            'expense' => ['cost_of_goods_sold', 'expenses', 'other_expense'],
            'liability' => ['other_current_liabilities', 'long_term_liabilities', 'credit_card'],
            'deductionCredit' => ['income', 'other_income', 'other_current_liabilities', 'long_term_liabilities'],
            default => [],
        };

        $sections = QuickBooksChartOfAccounts::sections();
        $result = [];

        foreach ($keys as $key) {
            if (!isset($sections[$key])) {
                continue;
            }

            $result[$key] = [
                'label' => $sections[$key]['label'],
                'type'  => $sections[$key]['type'],
            ];
        }

        return $result;
    }

    /**
     * @return array<int, string>
     */
    public static function allowedTypesForListKey(string $listKey): array
    {
        return match ($listKey) {
            'expense' => ['expense'],
            'liability' => ['liability'],
            'deductionCredit' => ['income', 'liability'],
            default => [],
        };
    }

    /**
     * @return array<string, array<int, array<string, mixed>>>
     */
    public static function salaryComponentAccountTrees(int $companyId): array
    {
        return [
            'expense'         => AccountPickerTreeBuilder::build($companyId, ['expense']),
            'liability'       => AccountPickerTreeBuilder::build($companyId, ['liability']),
            'deductionCredit' => AccountPickerTreeBuilder::build($companyId, ['income', 'liability']),
        ];
    }
}
