package hr.com.port.ips.eracun.provider.mer.enums;

public enum MerIdentifierType {
    OIB(0),
    GLN(1);

    private final int code;

    MerIdentifierType(int code) {
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    /** Vrijednost za API pozive (kao String, jer query param je string) */
    public String apiValue() {
        return String.valueOf(code);
    }

    public static MerIdentifierType fromCode(int code) {
        switch (code) {
            case 0: return OIB;
            case 1: return GLN;
            default: throw new IllegalArgumentException("Nepoznat IdentifierType code: " + code);
        }
    }

    /** Backward kompatibilnost sa starim string vrijednostima iz v1.5 */
    public static MerIdentifierType parse(String v) {
        if (v == null) return null;
        String s = v.trim();
        if ("0".equals(s) || "OIB".equalsIgnoreCase(s)) return OIB;
        if ("1".equals(s) || "GLN".equalsIgnoreCase(s)) return GLN;
        throw new IllegalArgumentException("Nepoznat IdentifierType value: " + v);
    }
}