"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MagickFormatInfo = void 0;
const image_magick_1 = require("./image-magick");
const exception_1 = require("./exception/exception");
const pointer_1 = require("./pointer/pointer");
const magick_format_1 = require("./magick-format");
const string_1 = require("./native/string");
class MagickFormatInfo {
    constructor(format, description, isReadable, isWritable) {
        this._format = format;
        this._description = description;
        this._isReadable = isReadable;
        this._isWritable = isWritable;
    }
    get description() { return this._description; }
    get format() { return this._format; }
    get isReadable() { return this._isReadable; }
    get isWritable() { return this._isWritable; }
    static get all() {
        return exception_1.Exception.usePointer(exception => {
            return pointer_1.Pointer.use(pointer => {
                const list = image_magick_1.ImageMagick._api._MagickFormatInfo_CreateList(pointer.ptr, exception);
                const count = pointer.value;
                try {
                    const result = new Array(count);
                    const values = Object.values(magick_format_1.MagickFormat);
                    for (let i = 0; i < count; i++) {
                        const info = image_magick_1.ImageMagick._api._MagickFormatInfo_GetInfo(list, i, exception);
                        const formatName = string_1._createString(image_magick_1.ImageMagick._api._MagickFormatInfo_Format_Get(info));
                        const format = MagickFormatInfo.convertFormat(formatName, values);
                        const description = string_1._createString(image_magick_1.ImageMagick._api._MagickFormatInfo_Description_Get(info), '');
                        const isReadable = image_magick_1.ImageMagick._api._MagickFormatInfo_IsReadable_Get(info) == 1;
                        const isWritable = image_magick_1.ImageMagick._api._MagickFormatInfo_IsWritable_Get(info) == 1;
                        result[i] = new MagickFormatInfo(format, description, isReadable, isWritable);
                    }
                    return result;
                }
                finally {
                    image_magick_1.ImageMagick._api._MagickFormatInfo_DisposeList(list, count);
                }
            });
        });
    }
    static convertFormat(formatName, values) {
        if (formatName === null)
            return magick_format_1.MagickFormat.Unknown;
        if (values.includes(formatName))
            return formatName;
        return magick_format_1.MagickFormat.Unknown;
    }
}
exports.MagickFormatInfo = MagickFormatInfo;
