package p.packer.messages.assets;

import java.util.Locale;

public enum AssetFamilyCatalog {
    GLYPH_BANK("glyph_bank"),
    SCENE_BANK("scene_bank"),
    SOUND_BANK("sound_bank"),
    UNKNOWN("unknown");

    private final String manifestType;

    AssetFamilyCatalog(String manifestType) {
        this.manifestType = manifestType;
    }

    public String manifestType() {
        return manifestType;
    }

    public boolean matchesQuery(String normalizedQuery) {
        return manifestType.contains(normalizedQuery);
    }

    public static AssetFamilyCatalog fromManifestType(String manifestType) {
        if (manifestType == null) {
            return UNKNOWN;
        }
        final String normalized = manifestType.trim().toLowerCase(Locale.ROOT);
        for (AssetFamilyCatalog candidate : values()) {
            if (candidate == UNKNOWN) {
                continue;
            }
            if (candidate.manifestType.equals(normalized)) {
                return candidate;
            }
        }
        return UNKNOWN;
    }
}
