package com.market.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * Market HTTP 接口文案（与 spot 相同的 9 语与 {@link I18nLangKeys} 键规则）。
 */
public enum MessageCode {

    SUCCESS(0,
            "成功", "成功", "Success",
            "성공", "成功", "Erfolg",
            "Succès", "Successo", "Éxito");

    private final int code;
    private final Map<String, String> messages;

    MessageCode(int code,
                String zhCN, String zhHK, String enUS,
                String koKR, String jaJP, String deDE,
                String frFR, String itIT, String esES) {
        this.code = code;
        this.messages = new HashMap<>(16);
        this.messages.put("ZHCN", zhCN);
        this.messages.put("ZHHK", zhHK);
        this.messages.put("ENUS", enUS);
        this.messages.put("KOKR", koKR);
        this.messages.put("JAJP", jaJP);
        this.messages.put("DEDE", deDE);
        this.messages.put("FRFR", frFR);
        this.messages.put("ITIT", itIT);
        this.messages.put("ESES", esES);
    }

    public int getCode() {
        return code;
    }

    public String getMessage(String lang) {
        String key = I18nLangKeys.normalize(lang);
        String msg = messages.get(key);
        return msg != null ? msg : messages.get(I18nLangKeys.DEFAULT);
    }
}
