<?php declare(strict_types=1);

namespace App\Enums;

use Illuminate\Support\Collection;

enum Lang: int
{
    case Ru = 1;
    case En = 2;

    public function getTitle(): string
    {
        return match ($this) {
            self::Ru => 'Русский',
            self::En => 'English'
        };
    }

    public function getLocale(): string
    {
        return match ($this) {
            self::Ru => 'ru',
            self::En => 'en'
        };
    }

    public static function toArray(): array
    {
        $choices = [];
        foreach (self::cases() as $lang) {
            $choices[] = [
                'name' => $lang->name,
                'value' => $lang->value,
                'title' => $lang->getTitle(),
                'locale' => $lang->getLocale()
            ];
        }
        return $choices;
    }

    public static function toCollection(): Collection
    {
        return collect(self::toArray());
    }
}