import WhatwgMIMEType from "whatwg-mimetype";
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
export class MediaType {
    type;
    subtype;
    essence;
    parameters;
    mimeType;
    input;
    constructor(type, subtype, essence, parameters, mimeType, input) {
        this.type = type;
        this.subtype = subtype;
        this.essence = essence;
        this.parameters = parameters;
        this.mimeType = mimeType;
        this.input = input;
    }
    static APPLICATION_JSON = "application/json";
    static APPLICATION_OCTET_STREAM = "application/octet-stream";
    static MULTIPART_FORM_DATA = "multipart/form-data";
    static parse(input) {
        if (input == null) {
            return null;
        }
        const parsed = WhatwgMIMEType.parse(input);
        if (parsed == null) {
            return null;
        }
        return new MediaType(parsed.type, parsed.subtype, parsed.essence, parsed.parameters, parsed, input);
    }
    toString() {
        return this.input;
    }
    /** Types */
    isText() {
        return this.type === "text";
    }
    isImage() {
        return this.type === "image";
    }
    isAudio() {
        return this.type === "audio";
    }
    isVideo() {
        return this.type === "video";
    }
    isFont() {
        return this.type === "font";
    }
    isMultipart() {
        return this.type === "multipart";
    }
    isApplication() {
        return this.type === "application";
    }
    isMessage() {
        return this.type === "message";
    }
    isModel() {
        return this.type === "model";
    }
    /** Text */
    isCSS() {
        return this.isText() && this.subtype === "css";
    }
    isCSV() {
        return this.isText() && this.subtype === "csv";
    }
    isMarkdown() {
        return this.isText() && this.subtype === "markdown";
    }
    isPlainText() {
        return this.isText() && this.subtype === "plain";
    }
    isEventStream() {
        return this.isText() && this.subtype === "event-stream";
    }
    /** Multipart */
    isMultiPartFormData() {
        return this.isMultipart() && this.subtype === "form-data";
    }
    /** Application */
    isJSON() {
        return this.isApplication() && this.subtype === "json";
    }
    containsJSON() {
        return this.isApplication() && this.subtype.includes("json");
    }
    isURLEncoded() {
        return this.isApplication() && this.subtype === "x-www-form-urlencoded";
    }
    isOctetStream() {
        return this.isApplication() && this.subtype === "octet-stream";
    }
    isPDF() {
        return this.isApplication() && this.subtype === "pdf";
    }
    isZip() {
        return this.isApplication() && this.subtype === "zip";
    }
    isGzip() {
        return this.isApplication() && this.subtype === "gzip";
    }
    isTar() {
        return this.isApplication() && this.subtype === "tar";
    }
    isBrotli() {
        return this.isApplication() && this.subtype === "br";
    }
    isDeflate() {
        return this.isApplication() && this.subtype === "deflate";
    }
    isProtobuf() {
        return this.isApplication() && this.subtype === "protobuf";
    }
    /** Images */
    isAvif() {
        return this.isImage() && this.subtype === "avif";
    }
    isWebP() {
        return this.isImage() && this.subtype === "webp";
    }
    isSVG() {
        return this.isImage() && this.subtype === "svg+xml";
    }
    isPNG() {
        return this.isImage() && this.subtype === "png";
    }
    isJPEG() {
        return this.isImage() && this.subtype === "jpeg";
    }
    isGIF() {
        return this.isImage() && this.subtype === "gif";
    }
    /** Audio */
    isMPEG() {
        return this.isAudio() && this.subtype === "mpeg";
    }
    isWAV() {
        return this.isAudio() && this.subtype === "wav";
    }
    /** Mixed */
    isHTML() {
        return this.mimeType.isHTML();
    }
    isXML() {
        return this.mimeType.isXML();
    }
    isJavaScript() {
        return this.mimeType.isJavaScript();
    }
}
