<?php

namespace App\Support;

class ExpenseCategoryLabels
{
    public const RENT = 'rent';

    public const FUEL = 'fuel';

    public const OIL = 'oil';

    public const ELECTRICITY = 'electricity';

    public const INTERNET = 'internet';

    public const WATER = 'water';

    public const OFFICE_SUPPLIES = 'office_supplies';

    public const STAFF_MEALS = 'staff_meals';

    public const TRANSPORT = 'transport';

    public const REPAIRS = 'repairs';

    public const CLEANING = 'cleaning';

    public const MISCELLANEOUS = 'miscellaneous';

    /**
     * @return list<string>
     */
    public static function slugs(): array
    {
        return [
            self::RENT,
            self::FUEL,
            self::OIL,
            self::ELECTRICITY,
            self::INTERNET,
            self::WATER,
            self::OFFICE_SUPPLIES,
            self::STAFF_MEALS,
            self::TRANSPORT,
            self::REPAIRS,
            self::CLEANING,
            self::MISCELLANEOUS,
        ];
    }

    /**
     * @return array<string, array{slug: string, name: string}>
     */
    public static function defaultCategories(): array
    {
        return [
            'اجاره' => ['slug' => self::RENT, 'name' => 'Rent'],
            'سوخت' => ['slug' => self::FUEL, 'name' => 'Fuel'],
            'روغن' => ['slug' => self::OIL, 'name' => 'Oil'],
            'برق' => ['slug' => self::ELECTRICITY, 'name' => 'Electricity'],
            'اینترنت' => ['slug' => self::INTERNET, 'name' => 'Internet'],
            'آب' => ['slug' => self::WATER, 'name' => 'Water'],
            'لوازم اداری' => ['slug' => self::OFFICE_SUPPLIES, 'name' => 'Office supplies'],
            'غذای کارکنان' => ['slug' => self::STAFF_MEALS, 'name' => 'Staff meals'],
            'حمل‌ونقل' => ['slug' => self::TRANSPORT, 'name' => 'Transport'],
            'تعمیرات' => ['slug' => self::REPAIRS, 'name' => 'Repairs'],
            'نظافت' => ['slug' => self::CLEANING, 'name' => 'Cleaning'],
            'متفرقه' => ['slug' => self::MISCELLANEOUS, 'name' => 'Miscellaneous'],
            'Rent' => ['slug' => self::RENT, 'name' => 'Rent'],
            'Fuel' => ['slug' => self::FUEL, 'name' => 'Fuel'],
            'Oil' => ['slug' => self::OIL, 'name' => 'Oil'],
            'Electricity' => ['slug' => self::ELECTRICITY, 'name' => 'Electricity'],
            'Internet' => ['slug' => self::INTERNET, 'name' => 'Internet'],
            'Water' => ['slug' => self::WATER, 'name' => 'Water'],
            'Office supplies' => ['slug' => self::OFFICE_SUPPLIES, 'name' => 'Office supplies'],
            'Staff meals' => ['slug' => self::STAFF_MEALS, 'name' => 'Staff meals'],
            'Transport' => ['slug' => self::TRANSPORT, 'name' => 'Transport'],
            'Repairs' => ['slug' => self::REPAIRS, 'name' => 'Repairs'],
            'Cleaning' => ['slug' => self::CLEANING, 'name' => 'Cleaning'],
            'Miscellaneous' => ['slug' => self::MISCELLANEOUS, 'name' => 'Miscellaneous'],
        ];
    }

    public static function label(?string $slug, ?string $fallbackName = null): string
    {
        if ($slug !== null && $slug !== '') {
            $key = 'expense_categories.'.$slug;
            $translated = __($key);

            if ($translated !== $key) {
                return $translated;
            }
        }

        return $fallbackName ?? '';
    }
}
