<?php

namespace App\Enums;

use App\Enums\Traits\HasLabels;

enum SongLanguageType: string
{
    use HasLabels;

    case Unset = '未定義';
    case Mandarin = '國語';
    case Taiwanese = '台語';
    case English = '英語'; 
    case Japanese = '日語'; 
    case Cantonese = '粵語'; 
    case Korean = '韓語'; 
    case Vietnamese = '越語'; 
    case Hakka = '客語'; 
    case Other = '其他'; 

    // 返回對應的顯示文字
    public function labels(): string
    {
        return match($this) {
            self::Unset => __('enums.Unset'),
            self::Mandarin => __('enums.song.LanguageType.Mandarin'),
            self::Taiwanese => __('enums.song.LanguageType.Taiwanese'),
            self::English => __('enums.song.LanguageType.English'),
            self::Japanese => __('enums.song.LanguageType.Japanese'),
            self::Cantonese => __('enums.song.LanguageType.Cantonese'),
            self::Korean => __('enums.song.LanguageType.Korean'),
            self::Vietnamese => __('enums.song.LanguageType.Vietnamese'),
            self::Hakka => __('enums.song.LanguageType.Hakka'),
            self::Other => __('enums.song.LanguageType.Other'),
        };
    }
    public static function fromLabelOrName(string $input): self
    {
        $aliasMap = [
            '英文' => '英語',
            '華語' => '國語',
            '普通話' => '國語',
            '台灣話' => '台語',
            '客家話' => '客語',
        ];
        // 將別名轉為正式值
        $input = $aliasMap[$input] ?? $input;
        foreach (self::cases() as $case) {
            if ($case->value === $input || $case->name === $input) {
                return $case;
            }
        }
        return self::Unset;
    }
}