// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
// Trust me, you don't want to mess with it!

import {
  ArrayBufferDataStream,
  FfiConverter,
  FfiConverterArrayBuffer,
  FfiConverterInt8,
  FfiConverterUInt8,
  FfiConverterInt16,
  FfiConverterUInt16,
  FfiConverterInt32,
  FfiConverterUInt32,
  FfiConverterInt64,
  FfiConverterUInt64,
  FfiConverterFloat32,
  FfiConverterFloat64,
  FfiConverterBoolean,
  FfiConverterBytes,
  FfiConverterString,
  UniFFICallbackHandler,
  UniFFICallbackMethodHandler,
  UniFFIError,
  UniFFIInternalError,
  UniFFITypeError,
  constructUniffiObject,
  handleRustResult,
  uniffiObjectPtr,
} from "moz-src:///toolkit/components/uniffi-js/js/UniFFI.sys.mjs";

// Objects intended to be used in the unit tests
export var UnitTestObjs = {
    uniffiObjectPtr,
};





/**
 * Attachment metadata that can be optionally attached to a [Record]. The [location] should
 * included in calls to [Client::get_attachment].
 */
export class Attachment {
    constructor(
        {
            filename, 
            mimetype, 
            location, 
            hash, 
            size
        } = {
            filename: undefined, 
            mimetype: undefined, 
            location: undefined, 
            hash: undefined, 
            size: undefined
        }
    ) {
        try {
            FfiConverterString.checkType(filename)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("filename");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(mimetype)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("mimetype");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(location)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("location");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(hash)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("hash");
            }
            throw e;
        }
        try {
            FfiConverterUInt64.checkType(size)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("size");
            }
            throw e;
        }
        /**
         * @type {string}
         */
        this.filename = filename;
        /**
         * @type {string}
         */
        this.mimetype = mimetype;
        /**
         * @type {string}
         */
        this.location = location;
        /**
         * @type {string}
         */
        this.hash = hash;
        /**
         * @type {number}
         */
        this.size = size;
    }

    equals(other) {
        return (
            this.filename == other.filename
            && this.mimetype == other.mimetype
            && this.location == other.location
            && this.hash == other.hash
            && this.size == other.size
        )
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeAttachment extends FfiConverterArrayBuffer {
    static read(dataStream) {
        return new Attachment({
            filename: FfiConverterString.read(dataStream),
            mimetype: FfiConverterString.read(dataStream),
            location: FfiConverterString.read(dataStream),
            hash: FfiConverterString.read(dataStream),
            size: FfiConverterUInt64.read(dataStream),
        });
    }
    static write(dataStream, value) {
        FfiConverterString.write(dataStream, value.filename);
        FfiConverterString.write(dataStream, value.mimetype);
        FfiConverterString.write(dataStream, value.location);
        FfiConverterString.write(dataStream, value.hash);
        FfiConverterUInt64.write(dataStream, value.size);
    }

    static computeSize(value) {
        let totalSize = 0;
        totalSize += FfiConverterString.computeSize(value.filename);
        totalSize += FfiConverterString.computeSize(value.mimetype);
        totalSize += FfiConverterString.computeSize(value.location);
        totalSize += FfiConverterString.computeSize(value.hash);
        totalSize += FfiConverterUInt64.computeSize(value.size);
        return totalSize
    }

    static checkType(value) {
        super.checkType(value);
        if (!(value instanceof Attachment)) {
            throw new UniFFITypeError(`Expected 'Attachment', found '${typeof value}'`);
        }
        try {
            FfiConverterString.checkType(value.filename);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".filename");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(value.mimetype);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".mimetype");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(value.location);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".location");
            }
            throw e;
        }
        try {
            FfiConverterString.checkType(value.hash);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".hash");
            }
            throw e;
        }
        try {
            FfiConverterUInt64.checkType(value.size);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".size");
            }
            throw e;
        }
    }
}

/**
 * The Remote Settings server that the client should use.
 */
export class RemoteSettingsServer {}
/**
 * Prod
 */
RemoteSettingsServer.Prod = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * ProdV2
 */
RemoteSettingsServer.ProdV2 = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * Stage
 */
RemoteSettingsServer.Stage = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * StageV2
 */
RemoteSettingsServer.StageV2 = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * Dev
 */
RemoteSettingsServer.Dev = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * DevV2
 */
RemoteSettingsServer.DevV2 = class extends RemoteSettingsServer{
   constructor() {
            super();
    }
}
/**
 * Custom
 */
RemoteSettingsServer.Custom = class extends RemoteSettingsServer{
   constructor({url = undefined } = {}) {
                super();
            try {
                FfiConverterString.checkType(url);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart("url");
                }
                throw e;
            }
            this.url = url;
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsServer extends FfiConverterArrayBuffer {
    static read(dataStream) {
        // Use sequential indices (1-based) for the wire format to match the Rust scaffolding
        switch (dataStream.readInt32()) {
            case 1:
                return new RemoteSettingsServer.Prod();
            case 2:
                return new RemoteSettingsServer.ProdV2();
            case 3:
                return new RemoteSettingsServer.Stage();
            case 4:
                return new RemoteSettingsServer.StageV2();
            case 5:
                return new RemoteSettingsServer.Dev();
            case 6:
                return new RemoteSettingsServer.DevV2();
            case 7:
                return new RemoteSettingsServer.Custom({
                    url: FfiConverterString.read(dataStream)
                });
            default:
                throw new UniFFITypeError("Unknown RemoteSettingsServer variant");
        }
    }

    static write(dataStream, value) {
        // Use sequential indices (1-based) for the wire format to match the Rust scaffolding
        if (value instanceof RemoteSettingsServer.Prod) {
            dataStream.writeInt32(1);
            return;
        }
        if (value instanceof RemoteSettingsServer.ProdV2) {
            dataStream.writeInt32(2);
            return;
        }
        if (value instanceof RemoteSettingsServer.Stage) {
            dataStream.writeInt32(3);
            return;
        }
        if (value instanceof RemoteSettingsServer.StageV2) {
            dataStream.writeInt32(4);
            return;
        }
        if (value instanceof RemoteSettingsServer.Dev) {
            dataStream.writeInt32(5);
            return;
        }
        if (value instanceof RemoteSettingsServer.DevV2) {
            dataStream.writeInt32(6);
            return;
        }
        if (value instanceof RemoteSettingsServer.Custom) {
            dataStream.writeInt32(7);
            FfiConverterString.write(dataStream, value.url);
            return;
        }
        throw new UniFFITypeError("Unknown RemoteSettingsServer variant");
    }

    static computeSize(value) {
        // Size of the Int indicating the variant
        let totalSize = 4;
        if (value instanceof RemoteSettingsServer.Prod) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.ProdV2) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.Stage) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.StageV2) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.Dev) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.DevV2) {
            return totalSize;
        }
        if (value instanceof RemoteSettingsServer.Custom) {
            totalSize += FfiConverterString.computeSize(value.url);
            return totalSize;
        }
        throw new UniFFITypeError("Unknown RemoteSettingsServer variant");
    }

    static checkType(value) {
      if (!(value instanceof RemoteSettingsServer)) {
        throw new UniFFITypeError(`${value} is not a subclass instance of RemoteSettingsServer`);
      }
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeRemoteSettingsServer extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterTypeRemoteSettingsServer.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterTypeRemoteSettingsServer.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterTypeRemoteSettingsServer.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterTypeRemoteSettingsServer.computeSize(value)
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalString extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterString.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterString.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterString.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterString.computeSize(value)
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterMapStringString extends FfiConverterArrayBuffer {
    static read(dataStream) {
        const len = dataStream.readInt32();
        const map = new Map();
        for (let i = 0; i < len; i++) {
            const key = FfiConverterString.read(dataStream);
            const value = FfiConverterString.read(dataStream);
            map.set(key, value);
        }

        return map;
    }

     static write(dataStream, map) {
        dataStream.writeInt32(map.size);
        for (const [key, value] of map) {
            FfiConverterString.write(dataStream, key);
            FfiConverterString.write(dataStream, value);
        }
    }

    static computeSize(map) {
        // The size of the length
        let size = 4;
        for (const [key, value] of map) {
            size += FfiConverterString.computeSize(key);
            size += FfiConverterString.computeSize(value);
        }
        return size;
    }

    static checkType(map) {
        for (const [key, value] of map) {
            try {
                FfiConverterString.checkType(key);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart("(key)");
                }
                throw e;
            }

            try {
                FfiConverterString.checkType(value);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart(`[${key}]`);
                }
                throw e;
            }
        }
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalMapStringString extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterMapStringString.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterMapStringString.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterMapStringString.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterMapStringString.computeSize(value)
    }
}
/**
 * Remote settings context object
 * 
 * This is used to filter the records returned. We always fetch all `records` from the
 * remote-settings storage. Some records could have a `filter_expression`.  If this is passed in
 * and the record has a `filter_expression`, then only returns where the expression is true will
 * be returned.
 * 
 * See https://remote-settings.readthedocs.io/en/latest/target-filters.html for details.
 */
export class RemoteSettingsContext {
    constructor(
        {
            channel= null, 
            appVersion= null, 
            appId= null, 
            locale= null, 
            os= null, 
            osVersion= null, 
            formFactor= null, 
            country= null, 
            customTargettingAttributes= null
        } = {
            channel: undefined, 
            appVersion: undefined, 
            appId: undefined, 
            locale: undefined, 
            os: undefined, 
            osVersion: undefined, 
            formFactor: undefined, 
            country: undefined, 
            customTargettingAttributes: undefined
        }
    ) {
        try {
            FfiConverterOptionalString.checkType(channel)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("channel");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(appVersion)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("appVersion");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(appId)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("appId");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(locale)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("locale");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(os)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("os");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(osVersion)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("osVersion");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(formFactor)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("formFactor");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(country)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("country");
            }
            throw e;
        }
        try {
            FfiConverterOptionalMapStringString.checkType(customTargettingAttributes)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("customTargettingAttributes");
            }
            throw e;
        }
        /**
         * The delivery channel of the application (e.g "nightly")
         * @type {?string}
         */
        this.channel = channel;
        /**
         * User visible version string (e.g. "1.0.3")
         * @type {?string}
         */
        this.appVersion = appVersion;
        /**
         * String containing the XUL application app_id
         * @type {?string}
         */
        this.appId = appId;
        /**
         * The locale of the application during initialization (e.g. "es-ES")
         * @type {?string}
         */
        this.locale = locale;
        /**
         * The name of the operating system (e.g. "Android", "iOS", "Darwin", "WINNT")
         * @type {?string}
         */
        this.os = os;
        /**
         * The user-visible version of the operating system (e.g. "1.2.3")
         * @type {?string}
         */
        this.osVersion = osVersion;
        /**
         * Form-factor of the device ("phone", "tablet", or "desktop")
         * @type {?string}
         */
        this.formFactor = formFactor;
        /**
         * Country of the user.
         * 
         * This is usually populated in one of two ways:
         * - The second component of the locale
         * - By using a geolocation service, which determines country via the user's IP.
         * Firefox apps usually have a module that integrates with these services,
         * for example `Region` on Desktop and `RegionMiddleware` on Android.
         * @type {?string}
         */
        this.country = country;
        /**
         * Extra attributes to add to the env for JEXL filtering.
         * 
         * Use this for prototyping / testing new features.  In the long-term, new fields should be
         * added to the official list and supported by both the Rust and Gecko clients.
         * @type {?object}
         */
        this.customTargettingAttributes = customTargettingAttributes;
    }

    equals(other) {
        return (
            this.channel == other.channel
            && this.appVersion == other.appVersion
            && this.appId == other.appId
            && this.locale == other.locale
            && this.os == other.os
            && this.osVersion == other.osVersion
            && this.formFactor == other.formFactor
            && this.country == other.country
            && this.customTargettingAttributes == other.customTargettingAttributes
        )
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsContext extends FfiConverterArrayBuffer {
    static read(dataStream) {
        return new RemoteSettingsContext({
            channel: FfiConverterOptionalString.read(dataStream),
            appVersion: FfiConverterOptionalString.read(dataStream),
            appId: FfiConverterOptionalString.read(dataStream),
            locale: FfiConverterOptionalString.read(dataStream),
            os: FfiConverterOptionalString.read(dataStream),
            osVersion: FfiConverterOptionalString.read(dataStream),
            formFactor: FfiConverterOptionalString.read(dataStream),
            country: FfiConverterOptionalString.read(dataStream),
            customTargettingAttributes: FfiConverterOptionalMapStringString.read(dataStream),
        });
    }
    static write(dataStream, value) {
        FfiConverterOptionalString.write(dataStream, value.channel);
        FfiConverterOptionalString.write(dataStream, value.appVersion);
        FfiConverterOptionalString.write(dataStream, value.appId);
        FfiConverterOptionalString.write(dataStream, value.locale);
        FfiConverterOptionalString.write(dataStream, value.os);
        FfiConverterOptionalString.write(dataStream, value.osVersion);
        FfiConverterOptionalString.write(dataStream, value.formFactor);
        FfiConverterOptionalString.write(dataStream, value.country);
        FfiConverterOptionalMapStringString.write(dataStream, value.customTargettingAttributes);
    }

    static computeSize(value) {
        let totalSize = 0;
        totalSize += FfiConverterOptionalString.computeSize(value.channel);
        totalSize += FfiConverterOptionalString.computeSize(value.appVersion);
        totalSize += FfiConverterOptionalString.computeSize(value.appId);
        totalSize += FfiConverterOptionalString.computeSize(value.locale);
        totalSize += FfiConverterOptionalString.computeSize(value.os);
        totalSize += FfiConverterOptionalString.computeSize(value.osVersion);
        totalSize += FfiConverterOptionalString.computeSize(value.formFactor);
        totalSize += FfiConverterOptionalString.computeSize(value.country);
        totalSize += FfiConverterOptionalMapStringString.computeSize(value.customTargettingAttributes);
        return totalSize
    }

    static checkType(value) {
        super.checkType(value);
        if (!(value instanceof RemoteSettingsContext)) {
            throw new UniFFITypeError(`Expected 'RemoteSettingsContext', found '${typeof value}'`);
        }
        try {
            FfiConverterOptionalString.checkType(value.channel);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".channel");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.appVersion);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".appVersion");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.appId);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".appId");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.locale);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".locale");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.os);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".os");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.osVersion);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".osVersion");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.formFactor);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".formFactor");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.country);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".country");
            }
            throw e;
        }
        try {
            FfiConverterOptionalMapStringString.checkType(value.customTargettingAttributes);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".customTargettingAttributes");
            }
            throw e;
        }
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeRemoteSettingsContext extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterTypeRemoteSettingsContext.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterTypeRemoteSettingsContext.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterTypeRemoteSettingsContext.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterTypeRemoteSettingsContext.computeSize(value)
    }
}
/**
 * Remote settings configuration
 */
export class RemoteSettingsConfig {
    constructor(
        {
            server= null, 
            bucketName= null, 
            appContext= null
        } = {
            server: undefined, 
            bucketName: undefined, 
            appContext: undefined
        }
    ) {
        try {
            FfiConverterOptionalTypeRemoteSettingsServer.checkType(server)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("server");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(bucketName)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("bucketName");
            }
            throw e;
        }
        try {
            FfiConverterOptionalTypeRemoteSettingsContext.checkType(appContext)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("appContext");
            }
            throw e;
        }
        /**
         * The Remote Settings server to use. Defaults to [RemoteSettingsServer::Prod],
         * @type {?RemoteSettingsServer[keyof RemoteSettingsServer]}
         */
        this.server = server;
        /**
         * Bucket name to use, defaults to "main".  Use "main-preview" for a preview bucket
         * @type {?string}
         */
        this.bucketName = bucketName;
        /**
         * App context to use for JEXL filtering (when the `jexl` feature is present).
         * @type {?RemoteSettingsContext}
         */
        this.appContext = appContext;
    }

    equals(other) {
        return (
            this.server == other.server
            && this.bucketName == other.bucketName
            && this.appContext == other.appContext
        )
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsConfig extends FfiConverterArrayBuffer {
    static read(dataStream) {
        return new RemoteSettingsConfig({
            server: FfiConverterOptionalTypeRemoteSettingsServer.read(dataStream),
            bucketName: FfiConverterOptionalString.read(dataStream),
            appContext: FfiConverterOptionalTypeRemoteSettingsContext.read(dataStream),
        });
    }
    static write(dataStream, value) {
        FfiConverterOptionalTypeRemoteSettingsServer.write(dataStream, value.server);
        FfiConverterOptionalString.write(dataStream, value.bucketName);
        FfiConverterOptionalTypeRemoteSettingsContext.write(dataStream, value.appContext);
    }

    static computeSize(value) {
        let totalSize = 0;
        totalSize += FfiConverterOptionalTypeRemoteSettingsServer.computeSize(value.server);
        totalSize += FfiConverterOptionalString.computeSize(value.bucketName);
        totalSize += FfiConverterOptionalTypeRemoteSettingsContext.computeSize(value.appContext);
        return totalSize
    }

    static checkType(value) {
        super.checkType(value);
        if (!(value instanceof RemoteSettingsConfig)) {
            throw new UniFFITypeError(`Expected 'RemoteSettingsConfig', found '${typeof value}'`);
        }
        try {
            FfiConverterOptionalTypeRemoteSettingsServer.checkType(value.server);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".server");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.bucketName);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".bucketName");
            }
            throw e;
        }
        try {
            FfiConverterOptionalTypeRemoteSettingsContext.checkType(value.appContext);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".appContext");
            }
            throw e;
        }
    }
}


// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalTypeAttachment extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterTypeAttachment.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterTypeAttachment.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterTypeAttachment.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterTypeAttachment.computeSize(value)
    }
}
export class FfiConverterTypeRsJsonObject extends FfiConverter {
    static lift(value) {
        return FfiConverterString.lift(value);
    }

    static lower(value) {
        return FfiConverterString.lower(value);
    }

    static write(dataStream, value) {
        FfiConverterString.write(dataStream, value);
    }

    static read(dataStream) {
        const builtinVal = FfiConverterString.read(dataStream);
        return builtinVal;
    }

    static computeSize(value) {
        return FfiConverterString.computeSize(value);
    }

    static checkType(value) {
        if (value === null || value === undefined) {
            throw new TypeError("value is null or undefined");
        }
    }
}
/**
 * A parsed Remote Settings record. Records can contain arbitrary fields, so clients
 * are required to further extract expected values from the [fields] member.
 */
export class RemoteSettingsRecord {
    constructor(
        {
            id, 
            lastModified, 
            deleted, 
            attachment, 
            fields
        } = {
            id: undefined, 
            lastModified: undefined, 
            deleted: undefined, 
            attachment: undefined, 
            fields: undefined
        }
    ) {
        try {
            FfiConverterString.checkType(id)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("id");
            }
            throw e;
        }
        try {
            FfiConverterUInt64.checkType(lastModified)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("lastModified");
            }
            throw e;
        }
        try {
            FfiConverterBoolean.checkType(deleted)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("deleted");
            }
            throw e;
        }
        try {
            FfiConverterOptionalTypeAttachment.checkType(attachment)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("attachment");
            }
            throw e;
        }
        try {
            FfiConverterTypeRsJsonObject.checkType(fields)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("fields");
            }
            throw e;
        }
        /**
         * @type {string}
         */
        this.id = id;
        /**
         * @type {number}
         */
        this.lastModified = lastModified;
        /**
         * Tombstone flag (see https://remote-settings.readthedocs.io/en/latest/client-specifications.html#local-state)
         * @type {boolean}
         */
        this.deleted = deleted;
        /**
         * @type {?Attachment}
         */
        this.attachment = attachment;
        /**
         * @type {RsJsonObject}
         */
        this.fields = fields;
    }

    equals(other) {
        return (
            this.id == other.id
            && this.lastModified == other.lastModified
            && this.deleted == other.deleted
            && this.attachment == other.attachment
            && this.fields == other.fields
        )
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsRecord extends FfiConverterArrayBuffer {
    static read(dataStream) {
        return new RemoteSettingsRecord({
            id: FfiConverterString.read(dataStream),
            lastModified: FfiConverterUInt64.read(dataStream),
            deleted: FfiConverterBoolean.read(dataStream),
            attachment: FfiConverterOptionalTypeAttachment.read(dataStream),
            fields: FfiConverterTypeRsJsonObject.read(dataStream),
        });
    }
    static write(dataStream, value) {
        FfiConverterString.write(dataStream, value.id);
        FfiConverterUInt64.write(dataStream, value.lastModified);
        FfiConverterBoolean.write(dataStream, value.deleted);
        FfiConverterOptionalTypeAttachment.write(dataStream, value.attachment);
        FfiConverterTypeRsJsonObject.write(dataStream, value.fields);
    }

    static computeSize(value) {
        let totalSize = 0;
        totalSize += FfiConverterString.computeSize(value.id);
        totalSize += FfiConverterUInt64.computeSize(value.lastModified);
        totalSize += FfiConverterBoolean.computeSize(value.deleted);
        totalSize += FfiConverterOptionalTypeAttachment.computeSize(value.attachment);
        totalSize += FfiConverterTypeRsJsonObject.computeSize(value.fields);
        return totalSize
    }

    static checkType(value) {
        super.checkType(value);
        if (!(value instanceof RemoteSettingsRecord)) {
            throw new UniFFITypeError(`Expected 'RemoteSettingsRecord', found '${typeof value}'`);
        }
        try {
            FfiConverterString.checkType(value.id);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".id");
            }
            throw e;
        }
        try {
            FfiConverterUInt64.checkType(value.lastModified);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".lastModified");
            }
            throw e;
        }
        try {
            FfiConverterBoolean.checkType(value.deleted);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".deleted");
            }
            throw e;
        }
        try {
            FfiConverterOptionalTypeAttachment.checkType(value.attachment);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".attachment");
            }
            throw e;
        }
        try {
            FfiConverterTypeRsJsonObject.checkType(value.fields);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".fields");
            }
            throw e;
        }
    }
}
/**
 * UptakeEventExtras
 */
export class UptakeEventExtras {
    constructor(
        {
            value, 
            source, 
            age, 
            trigger, 
            timestamp, 
            duration, 
            errorName
        } = {
            value: undefined, 
            source: undefined, 
            age: undefined, 
            trigger: undefined, 
            timestamp: undefined, 
            duration: undefined, 
            errorName: undefined
        }
    ) {
        try {
            FfiConverterOptionalString.checkType(value)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("value");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(source)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("source");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(age)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("age");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(trigger)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("trigger");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(timestamp)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("timestamp");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(duration)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("duration");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(errorName)
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart("errorName");
            }
            throw e;
        }
        /**
         * Main sync status.
         * @type {?string}
         */
        this.value = value;
        /**
         * Source of the sync (eg. "settings-changes-monitoring", "main/{collection}", ...)
         * @type {?string}
         */
        this.source = source;
        /**
         * Age of the data in milliseconds, if available.
         * @type {?string}
         */
        this.age = age;
        /**
         * Trigger that caused the sync (eg. "manual", "startup", "scheduled", ...) if available.
         * @type {?string}
         */
        this.trigger = trigger;
        /**
         * Timestamp received from the server, if available.
         * @type {?string}
         */
        this.timestamp = timestamp;
        /**
         * Duration of the sync operation in milliseconds, if available.
         * @type {?string}
         */
        this.duration = duration;
        /**
         * The name of the error that occurred, if available.
         * @type {?string}
         */
        this.errorName = errorName;
    }

    equals(other) {
        return (
            this.value == other.value
            && this.source == other.source
            && this.age == other.age
            && this.trigger == other.trigger
            && this.timestamp == other.timestamp
            && this.duration == other.duration
            && this.errorName == other.errorName
        )
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeUptakeEventExtras extends FfiConverterArrayBuffer {
    static read(dataStream) {
        return new UptakeEventExtras({
            value: FfiConverterOptionalString.read(dataStream),
            source: FfiConverterOptionalString.read(dataStream),
            age: FfiConverterOptionalString.read(dataStream),
            trigger: FfiConverterOptionalString.read(dataStream),
            timestamp: FfiConverterOptionalString.read(dataStream),
            duration: FfiConverterOptionalString.read(dataStream),
            errorName: FfiConverterOptionalString.read(dataStream),
        });
    }
    static write(dataStream, value) {
        FfiConverterOptionalString.write(dataStream, value.value);
        FfiConverterOptionalString.write(dataStream, value.source);
        FfiConverterOptionalString.write(dataStream, value.age);
        FfiConverterOptionalString.write(dataStream, value.trigger);
        FfiConverterOptionalString.write(dataStream, value.timestamp);
        FfiConverterOptionalString.write(dataStream, value.duration);
        FfiConverterOptionalString.write(dataStream, value.errorName);
    }

    static computeSize(value) {
        let totalSize = 0;
        totalSize += FfiConverterOptionalString.computeSize(value.value);
        totalSize += FfiConverterOptionalString.computeSize(value.source);
        totalSize += FfiConverterOptionalString.computeSize(value.age);
        totalSize += FfiConverterOptionalString.computeSize(value.trigger);
        totalSize += FfiConverterOptionalString.computeSize(value.timestamp);
        totalSize += FfiConverterOptionalString.computeSize(value.duration);
        totalSize += FfiConverterOptionalString.computeSize(value.errorName);
        return totalSize
    }

    static checkType(value) {
        super.checkType(value);
        if (!(value instanceof UptakeEventExtras)) {
            throw new UniFFITypeError(`Expected 'UptakeEventExtras', found '${typeof value}'`);
        }
        try {
            FfiConverterOptionalString.checkType(value.value);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".value");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.source);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".source");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.age);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".age");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.trigger);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".trigger");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.timestamp);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".timestamp");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.duration);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".duration");
            }
            throw e;
        }
        try {
            FfiConverterOptionalString.checkType(value.errorName);
        } catch (e) {
            if (e instanceof UniFFITypeError) {
                e.addItemDescriptionPart(".errorName");
            }
            throw e;
        }
    }
}

/**
 * Public error class, this is what we return to consumers
 */
export class RemoteSettingsError extends Error {}


/**
 * Network error while making a remote settings request
 */
export class Network extends RemoteSettingsError {

    constructor(
        reason,
        ...params
    ) {
        const message = `reason: ${ reason }`;
        super(message, ...params);
        this.reason = reason;
    }
    toString() {
        return `Network: ${super.toString()}`
    }
}

/**
 * The server has asked the client to backoff.
 */
export class Backoff extends RemoteSettingsError {

    constructor(
        seconds,
        ...params
    ) {
        const message = `seconds: ${ seconds }`;
        super(message, ...params);
        this.seconds = seconds;
    }
    toString() {
        return `Backoff: ${super.toString()}`
    }
}

/**
 * Other
 */
export class Other extends RemoteSettingsError {

    constructor(
        reason,
        ...params
    ) {
        const message = `reason: ${ reason }`;
        super(message, ...params);
        this.reason = reason;
    }
    toString() {
        return `Other: ${super.toString()}`
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsError extends FfiConverterArrayBuffer {
    static read(dataStream) {
        switch (dataStream.readInt32()) {
            case 1:
                return new Network(
                    FfiConverterString.read(dataStream)
                    );
            case 2:
                return new Backoff(
                    FfiConverterUInt64.read(dataStream)
                    );
            case 3:
                return new Other(
                    FfiConverterString.read(dataStream)
                    );
            default:
                throw new UniFFITypeError("Unknown RemoteSettingsError variant");
        }
    }
    static computeSize(value) {
        // Size of the Int indicating the variant
        let totalSize = 4;
        if (value instanceof Network) {
            totalSize += FfiConverterString.computeSize(value.reason);
            return totalSize;
        }
        if (value instanceof Backoff) {
            totalSize += FfiConverterUInt64.computeSize(value.seconds);
            return totalSize;
        }
        if (value instanceof Other) {
            totalSize += FfiConverterString.computeSize(value.reason);
            return totalSize;
        }
        throw new UniFFITypeError("Unknown RemoteSettingsError variant");
    }
    static write(dataStream, value) {
        if (value instanceof Network) {
            dataStream.writeInt32(1);
            FfiConverterString.write(dataStream, value.reason);
            return;
        }
        if (value instanceof Backoff) {
            dataStream.writeInt32(2);
            FfiConverterUInt64.write(dataStream, value.seconds);
            return;
        }
        if (value instanceof Other) {
            dataStream.writeInt32(3);
            FfiConverterString.write(dataStream, value.reason);
            return;
        }
        throw new UniFFITypeError("Unknown RemoteSettingsError variant");
    }

    static errorClass = RemoteSettingsError;
}

/**
 * Remote Settings sync status.
 */
export const SyncStatus = Object.freeze({
    /**
     * Sync completed and new data was stored.
     */
    SUCCESS: 0,
    /**
     * Local data is already up to date, no new data was stored.
     */
    UP_TO_DATE: 1,
    /**
     * A network-level error occurred (connection refused, timeout, bad HTTP status, ...)
     */
    NETWORK_ERROR: 2,
    /**
     * The server asked the client to back off.
     */
    BACKOFF_ERROR: 3,
    /**
     * Content signature verification failed.
     */
    SIGNATURE_ERROR: 4,
    /**
     * Server error (5xx status)
     */
    SERVER_ERROR: 5,
    /**
     * An unknown error occurred.
     */
    UNKNOWN_ERROR: 6,
});

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeSyncStatus extends FfiConverterArrayBuffer {
    static #validValues = Object.values(SyncStatus)

    static read(dataStream) {
        // Use sequential indices (1-based) for the wire format to match the Rust scaffolding
        switch (dataStream.readInt32()) {
            case 1:
                return SyncStatus.SUCCESS
            case 2:
                return SyncStatus.UP_TO_DATE
            case 3:
                return SyncStatus.NETWORK_ERROR
            case 4:
                return SyncStatus.BACKOFF_ERROR
            case 5:
                return SyncStatus.SIGNATURE_ERROR
            case 6:
                return SyncStatus.SERVER_ERROR
            case 7:
                return SyncStatus.UNKNOWN_ERROR
            default:
                throw new UniFFITypeError("Unknown SyncStatus variant");
        }
    }

    static write(dataStream, value) {
        // Use sequential indices (1-based) for the wire format to match the Rust scaffolding
        if (value === SyncStatus.SUCCESS) {
            dataStream.writeInt32(1);
            return;
        }
        if (value === SyncStatus.UP_TO_DATE) {
            dataStream.writeInt32(2);
            return;
        }
        if (value === SyncStatus.NETWORK_ERROR) {
            dataStream.writeInt32(3);
            return;
        }
        if (value === SyncStatus.BACKOFF_ERROR) {
            dataStream.writeInt32(4);
            return;
        }
        if (value === SyncStatus.SIGNATURE_ERROR) {
            dataStream.writeInt32(5);
            return;
        }
        if (value === SyncStatus.SERVER_ERROR) {
            dataStream.writeInt32(6);
            return;
        }
        if (value === SyncStatus.UNKNOWN_ERROR) {
            dataStream.writeInt32(7);
            return;
        }
        throw new UniFFITypeError("Unknown SyncStatus variant");
    }

    static computeSize(value) {
        return 4;
    }

    static checkType(value) {
      // Check that the value is a valid enum variant
      if (!this.#validValues.includes(value)) {
          throw new UniFFITypeError(`${value} is not a valid value for SyncStatus`);
      }
    }
}


// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalUInt64 extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterUInt64.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterUInt64.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterUInt64.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterUInt64.computeSize(value)
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceTypeRemoteSettingsRecord extends FfiConverterArrayBuffer {
    static read(dataStream) {
        const len = dataStream.readInt32();
        const arr = [];
        for (let i = 0; i < len; i++) {
            arr.push(FfiConverterTypeRemoteSettingsRecord.read(dataStream));
        }
        return arr;
    }

    static write(dataStream, value) {
        dataStream.writeInt32(value.length);
        value.forEach((innerValue) => {
            FfiConverterTypeRemoteSettingsRecord.write(dataStream, innerValue);
        })
    }

    static computeSize(value) {
        // The size of the length
        let size = 4;
        for (const innerValue of value) {
            size += FfiConverterTypeRemoteSettingsRecord.computeSize(innerValue);
        }
        return size;
    }

    static checkType(value) {
        if (!Array.isArray(value)) {
            throw new UniFFITypeError(`${value} is not an array`);
        }
        value.forEach((innerValue, idx) => {
            try {
                FfiConverterTypeRemoteSettingsRecord.checkType(innerValue);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart(`[${idx}]`);
                }
                throw e;
            }
        })
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalSequenceTypeRemoteSettingsRecord extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterSequenceTypeRemoteSettingsRecord.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterSequenceTypeRemoteSettingsRecord.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterSequenceTypeRemoteSettingsRecord.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterSequenceTypeRemoteSettingsRecord.computeSize(value)
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterMapStringTypeRemoteSettingsRecord extends FfiConverterArrayBuffer {
    static read(dataStream) {
        const len = dataStream.readInt32();
        const map = new Map();
        for (let i = 0; i < len; i++) {
            const key = FfiConverterString.read(dataStream);
            const value = FfiConverterTypeRemoteSettingsRecord.read(dataStream);
            map.set(key, value);
        }

        return map;
    }

     static write(dataStream, map) {
        dataStream.writeInt32(map.size);
        for (const [key, value] of map) {
            FfiConverterString.write(dataStream, key);
            FfiConverterTypeRemoteSettingsRecord.write(dataStream, value);
        }
    }

    static computeSize(map) {
        // The size of the length
        let size = 4;
        for (const [key, value] of map) {
            size += FfiConverterString.computeSize(key);
            size += FfiConverterTypeRemoteSettingsRecord.computeSize(value);
        }
        return size;
    }

    static checkType(map) {
        for (const [key, value] of map) {
            try {
                FfiConverterString.checkType(key);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart("(key)");
                }
                throw e;
            }

            try {
                FfiConverterTypeRemoteSettingsRecord.checkType(value);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart(`[${key}]`);
                }
                throw e;
            }
        }
    }
}
// Export the FFIConverter object to make external types work.
export class FfiConverterOptionalMapStringTypeRemoteSettingsRecord extends FfiConverterArrayBuffer {
    static checkType(value) {
        if (value !== undefined && value !== null) {
            FfiConverterMapStringTypeRemoteSettingsRecord.checkType(value)
        }
    }

    static read(dataStream) {
        const code = dataStream.readUint8(0);
        switch (code) {
            case 0:
                return null
            case 1:
                return FfiConverterMapStringTypeRemoteSettingsRecord.read(dataStream)
            default:
                throw new UniFFIError(`Unexpected code: ${code}`);
        }
    }

    static write(dataStream, value) {
        if (value === null || value === undefined) {
            dataStream.writeUint8(0);
            return;
        }
        dataStream.writeUint8(1);
        FfiConverterMapStringTypeRemoteSettingsRecord.write(dataStream, value)
    }

    static computeSize(value) {
        if (value === null || value === undefined) {
            return 1;
        }
        return 1 + FfiConverterMapStringTypeRemoteSettingsRecord.computeSize(value)
    }
}

/**
 * Client for a single Remote Settings collection
 * 
 * Use [RemoteSettingsService::make_client] to create these.
 */
export class RemoteSettingsClientInterface {
    /**
     * Collection this client is for
     * @returns {Promise<string>}}
     */
    async collectionName() {
      throw Error("collectionName not implemented");
    }
    /**
     * Get attachment data for a remote settings record
     * 
     * Attachments are large binary blobs used for data that doesn't fit in a normal record.  They
     * are handled differently than other record data:
     * 
     * - Attachments are not downloaded in [RemoteSettingsService::sync]
     * - This method will make network requests if the attachment is not cached
     * - This method will throw if there is a network or other error when fetching the
     * attachment data.
     * @param {RemoteSettingsRecord} record
     * @returns {Promise<string>}}
     */
    async getAttachment(
        record) {
      throw Error("getAttachment not implemented");
    }
    /**
     * Returns the last_modified value for the collection as an unsigned int64.
     * @returns {Promise<?number>}}
     */
    async getLastModifiedTimestamp() {
      throw Error("getLastModifiedTimestamp not implemented");
    }
    /**
     * Get the current set of records.
     * 
     * This method normally fetches records from the last sync.  This means that it returns fast
     * and does not make any network requests.
     * 
     * If records have not yet been synced it will return None.  Use `sync_if_empty = true` to
     * change this behavior and perform a network request in this case.  That this is probably a
     * bad idea if you want to fetch the setting in application startup or when building the UI.
     * 
     * None will also be returned on disk IO errors or other unexpected errors.  The reason for
     * this is that there is not much an application can do in this situation other than fall back
     * to the same default handling as if records have not been synced.
     * 
     * Application-services schedules regular dumps of the server data for specific collections.
     * For these collections, `get_records` will never return None.  If you would like to add your
     * collection to this list, please reach out to the DISCO team.
     * @param {boolean} syncIfEmpty
     * @returns {Promise<?Array.<RemoteSettingsRecord>>}}
     */
    async getRecords(
        syncIfEmpty = false) {
      throw Error("getRecords not implemented");
    }
    /**
     * Get the current set of records as a map of record_id -> record.
     * 
     * See [Self::get_records] for an explanation of when this makes network requests, error
     * handling, and how the `sync_if_empty` param works.
     * @param {boolean} syncIfEmpty
     * @returns {Promise<?object>}}
     */
    async getRecordsMap(
        syncIfEmpty = false) {
      throw Error("getRecordsMap not implemented");
    }
    /**
     * resetStorage
     */
    async resetStorage() {
      throw Error("resetStorage not implemented");
    }
    /**
     * Shutdown the client, releasing the SQLite connection used to cache records.
     */
    async shutdown() {
      throw Error("shutdown not implemented");
    }
    /**
     * sync
     */
    async sync() {
      throw Error("sync not implemented");
    }

}

/**
 * Client for a single Remote Settings collection
 * 
 * Use [RemoteSettingsService::make_client] to create these.
 */
export class RemoteSettingsClient extends RemoteSettingsClientInterface {
    // Use `init` to instantiate this class.
    // DO NOT USE THIS CONSTRUCTOR DIRECTLY
    constructor(opts) {
        super();
        if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
            throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
            "Please use a UDL defined constructor, or the init function for the primary constructor")
        }
        if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
            throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
        }
        this[uniffiObjectPtr] = opts[constructUniffiObject];
    }

    /**
     * Collection this client is for
     * @returns {Promise<string>}}
     */
    async collectionName() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            75, // uniffi_remote_settings_fn_method_remotesettingsclient_collection_name
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            FfiConverterString.lift.bind(FfiConverterString),
            null,
        )
    }

    /**
     * Get attachment data for a remote settings record
     * 
     * Attachments are large binary blobs used for data that doesn't fit in a normal record.  They
     * are handled differently than other record data:
     * 
     * - Attachments are not downloaded in [RemoteSettingsService::sync]
     * - This method will make network requests if the attachment is not cached
     * - This method will throw if there is a network or other error when fetching the
     * attachment data.
     * @param {RemoteSettingsRecord} record
     * @returns {Promise<string>}}
     */
    async getAttachment(
        record) {
       
        FfiConverterTypeRemoteSettingsRecord.checkType(record);
        const result = await UniFFIScaffolding.callAsyncWrapper(
            76, // uniffi_remote_settings_fn_method_remotesettingsclient_get_attachment
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
            FfiConverterTypeRemoteSettingsRecord.lower(record),
        )
        return handleRustResult(
            result,
            FfiConverterBytes.lift.bind(FfiConverterBytes),
            FfiConverterTypeRemoteSettingsError.lift.bind(FfiConverterTypeRemoteSettingsError),
        )
    }

    /**
     * Returns the last_modified value for the collection as an unsigned int64.
     * @returns {Promise<?number>}}
     */
    async getLastModifiedTimestamp() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            77, // uniffi_remote_settings_fn_method_remotesettingsclient_get_last_modified_timestamp
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            FfiConverterOptionalUInt64.lift.bind(FfiConverterOptionalUInt64),
            null,
        )
    }

    /**
     * Get the current set of records.
     * 
     * This method normally fetches records from the last sync.  This means that it returns fast
     * and does not make any network requests.
     * 
     * If records have not yet been synced it will return None.  Use `sync_if_empty = true` to
     * change this behavior and perform a network request in this case.  That this is probably a
     * bad idea if you want to fetch the setting in application startup or when building the UI.
     * 
     * None will also be returned on disk IO errors or other unexpected errors.  The reason for
     * this is that there is not much an application can do in this situation other than fall back
     * to the same default handling as if records have not been synced.
     * 
     * Application-services schedules regular dumps of the server data for specific collections.
     * For these collections, `get_records` will never return None.  If you would like to add your
     * collection to this list, please reach out to the DISCO team.
     * @param {boolean} syncIfEmpty
     * @returns {Promise<?Array.<RemoteSettingsRecord>>}}
     */
    async getRecords(
        syncIfEmpty = false) {
       
        FfiConverterBoolean.checkType(syncIfEmpty);
        const result = await UniFFIScaffolding.callAsyncWrapper(
            78, // uniffi_remote_settings_fn_method_remotesettingsclient_get_records
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
            FfiConverterBoolean.lower(syncIfEmpty),
        )
        return handleRustResult(
            result,
            FfiConverterOptionalSequenceTypeRemoteSettingsRecord.lift.bind(FfiConverterOptionalSequenceTypeRemoteSettingsRecord),
            null,
        )
    }

    /**
     * Get the current set of records as a map of record_id -> record.
     * 
     * See [Self::get_records] for an explanation of when this makes network requests, error
     * handling, and how the `sync_if_empty` param works.
     * @param {boolean} syncIfEmpty
     * @returns {Promise<?object>}}
     */
    async getRecordsMap(
        syncIfEmpty = false) {
       
        FfiConverterBoolean.checkType(syncIfEmpty);
        const result = await UniFFIScaffolding.callAsyncWrapper(
            79, // uniffi_remote_settings_fn_method_remotesettingsclient_get_records_map
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
            FfiConverterBoolean.lower(syncIfEmpty),
        )
        return handleRustResult(
            result,
            FfiConverterOptionalMapStringTypeRemoteSettingsRecord.lift.bind(FfiConverterOptionalMapStringTypeRemoteSettingsRecord),
            null,
        )
    }

    /**
     * resetStorage
     */
    async resetStorage() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            80, // uniffi_remote_settings_fn_method_remotesettingsclient_reset_storage
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            (result) => undefined,
            FfiConverterTypeRemoteSettingsError.lift.bind(FfiConverterTypeRemoteSettingsError),
        )
    }

    /**
     * Shutdown the client, releasing the SQLite connection used to cache records.
     */
    async shutdown() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            81, // uniffi_remote_settings_fn_method_remotesettingsclient_shutdown
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            (result) => undefined,
            null,
        )
    }

    /**
     * sync
     */
    async sync() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            82, // uniffi_remote_settings_fn_method_remotesettingsclient_sync
            FfiConverterTypeRemoteSettingsClient.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            (result) => undefined,
            FfiConverterTypeRemoteSettingsError.lift.bind(FfiConverterTypeRemoteSettingsError),
        )
    }

}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsClient extends FfiConverter {
    static lift(value) {
        const opts = {};
        opts[constructUniffiObject] = value;
        return new RemoteSettingsClient(opts);
    }

    static lower(value) {
        const ptr = value[uniffiObjectPtr];
        if (!(ptr instanceof UniFFIPointer)) {
            throw new UniFFITypeError("Object is not a 'RemoteSettingsClient' instance");
        }
        return ptr;
    }

    static lowerReceiver(value) {
        // This works exactly the same as lower for non-trait interfaces
        return this.lower(value);
    }

    static read(dataStream) {
        return this.lift(dataStream.readPointer(12));
    }

    static write(dataStream, value) {
        dataStream.writePointer(12, this.lower(value));
    }

    static computeSize(value) {
        return 8;
    }
}

// Export the FFIConverter object to make external types work.
export class FfiConverterSequenceString extends FfiConverterArrayBuffer {
    static read(dataStream) {
        const len = dataStream.readInt32();
        const arr = [];
        for (let i = 0; i < len; i++) {
            arr.push(FfiConverterString.read(dataStream));
        }
        return arr;
    }

    static write(dataStream, value) {
        dataStream.writeInt32(value.length);
        value.forEach((innerValue) => {
            FfiConverterString.write(dataStream, innerValue);
        })
    }

    static computeSize(value) {
        // The size of the length
        let size = 4;
        for (const innerValue of value) {
            size += FfiConverterString.computeSize(innerValue);
        }
        return size;
    }

    static checkType(value) {
        if (!Array.isArray(value)) {
            throw new UniFFITypeError(`${value} is not an array`);
        }
        value.forEach((innerValue, idx) => {
            try {
                FfiConverterString.checkType(innerValue);
            } catch (e) {
                if (e instanceof UniFFITypeError) {
                    e.addItemDescriptionPart(`[${idx}]`);
                }
                throw e;
            }
        })
    }
}

/**
 * Application-level Remote Settings manager.
 * 
 * This handles application-level operations, like syncing all the collections, and acts as a
 * factory for creating clients.
 */
export class RemoteSettingsServiceInterface {
    /**
     * clientUrl
     * @returns {string}
     */
    clientUrl() {
      throw Error("clientUrl not implemented");
    }
    /**
     * Create a new Remote Settings client
     * 
     * This method performs no IO or network requests and is safe to run in a main thread that can't be blocked.
     * @param {string} collectionName
     * @returns {Promise<RemoteSettingsClient>}}
     */
    async makeClient(
        collectionName) {
      throw Error("makeClient not implemented");
    }
    /**
     * Sync collections for all active clients
     * 
     * The returned list is the list of collections for which updates were seen
     * and then synced.
     * @returns {Promise<Array.<string>>}}
     */
    async sync() {
      throw Error("sync not implemented");
    }
    /**
     * Update the remote settings config
     * 
     * This will cause all current and future clients to use new config and will delete any stored
     * records causing the clients to return new results from the new config.
     * 
     * Only intended for QA/debugging.  Swapping the remote settings server in the middle of
     * execution can cause weird effects.
     * @param {RemoteSettingsConfig} config
     */
    async updateConfig(
        config) {
      throw Error("updateConfig not implemented");
    }

}

/**
 * Application-level Remote Settings manager.
 * 
 * This handles application-level operations, like syncing all the collections, and acts as a
 * factory for creating clients.
 */
export class RemoteSettingsService extends RemoteSettingsServiceInterface {
    // Use `init` to instantiate this class.
    // DO NOT USE THIS CONSTRUCTOR DIRECTLY
    constructor(opts) {
        super();
        if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) {
            throw new UniFFIError("Attempting to construct an int using the JavaScript constructor directly" +
            "Please use a UDL defined constructor, or the init function for the primary constructor")
        }
        if (!(opts[constructUniffiObject] instanceof UniFFIPointer)) {
            throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer")
        }
        this[uniffiObjectPtr] = opts[constructUniffiObject];
    }
    /**
     * Construct a [RemoteSettingsService]
     * 
     * This is typically done early in the application-startup process.
     * 
     * This method performs no IO or network requests and is safe to run in a main thread that
     * can't be blocked.
     * 
     * `storage_dir` is a directory to store SQLite files in -- one per collection. If the
     * directory does not exist, it will be created when the storage is first used. Only the
     * directory and the SQLite files will be created, any parent directories must already exist.
     * @param {string} storageDir
     * @param {RemoteSettingsConfig} config
     * @returns {RemoteSettingsService}
     */
    static init(
        storageDir, 
        config) {
       
        FfiConverterString.checkType(storageDir);
        FfiConverterTypeRemoteSettingsConfig.checkType(config);
        const result = UniFFIScaffolding.callSync(
            83, // uniffi_remote_settings_fn_constructor_remotesettingsservice_new
            FfiConverterString.lower(storageDir),
            FfiConverterTypeRemoteSettingsConfig.lower(config),
        )
        return handleRustResult(
            result,
            FfiConverterTypeRemoteSettingsService.lift.bind(FfiConverterTypeRemoteSettingsService),
            null,
        )
    }

    /**
     * clientUrl
     * @returns {string}
     */
    clientUrl() {
       
        const result = UniFFIScaffolding.callSync(
            84, // uniffi_remote_settings_fn_method_remotesettingsservice_client_url
            FfiConverterTypeRemoteSettingsService.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            FfiConverterString.lift.bind(FfiConverterString),
            null,
        )
    }

    /**
     * Create a new Remote Settings client
     * 
     * This method performs no IO or network requests and is safe to run in a main thread that can't be blocked.
     * @param {string} collectionName
     * @returns {Promise<RemoteSettingsClient>}}
     */
    async makeClient(
        collectionName) {
       
        FfiConverterString.checkType(collectionName);
        const result = await UniFFIScaffolding.callAsyncWrapper(
            85, // uniffi_remote_settings_fn_method_remotesettingsservice_make_client
            FfiConverterTypeRemoteSettingsService.lowerReceiver(this),
            FfiConverterString.lower(collectionName),
        )
        return handleRustResult(
            result,
            FfiConverterTypeRemoteSettingsClient.lift.bind(FfiConverterTypeRemoteSettingsClient),
            null,
        )
    }

    /**
     * Sync collections for all active clients
     * 
     * The returned list is the list of collections for which updates were seen
     * and then synced.
     * @returns {Promise<Array.<string>>}}
     */
    async sync() {
       
        const result = await UniFFIScaffolding.callAsyncWrapper(
            86, // uniffi_remote_settings_fn_method_remotesettingsservice_sync
            FfiConverterTypeRemoteSettingsService.lowerReceiver(this),
        )
        return handleRustResult(
            result,
            FfiConverterSequenceString.lift.bind(FfiConverterSequenceString),
            FfiConverterTypeRemoteSettingsError.lift.bind(FfiConverterTypeRemoteSettingsError),
        )
    }

    /**
     * Update the remote settings config
     * 
     * This will cause all current and future clients to use new config and will delete any stored
     * records causing the clients to return new results from the new config.
     * 
     * Only intended for QA/debugging.  Swapping the remote settings server in the middle of
     * execution can cause weird effects.
     * @param {RemoteSettingsConfig} config
     */
    async updateConfig(
        config) {
       
        FfiConverterTypeRemoteSettingsConfig.checkType(config);
        const result = await UniFFIScaffolding.callAsyncWrapper(
            87, // uniffi_remote_settings_fn_method_remotesettingsservice_update_config
            FfiConverterTypeRemoteSettingsService.lowerReceiver(this),
            FfiConverterTypeRemoteSettingsConfig.lower(config),
        )
        return handleRustResult(
            result,
            (result) => undefined,
            FfiConverterTypeRemoteSettingsError.lift.bind(FfiConverterTypeRemoteSettingsError),
        )
    }

}

// Export the FFIConverter object to make external types work.
export class FfiConverterTypeRemoteSettingsService extends FfiConverter {
    static lift(value) {
        const opts = {};
        opts[constructUniffiObject] = value;
        return new RemoteSettingsService(opts);
    }

    static lower(value) {
        const ptr = value[uniffiObjectPtr];
        if (!(ptr instanceof UniFFIPointer)) {
            throw new UniFFITypeError("Object is not a 'RemoteSettingsService' instance");
        }
        return ptr;
    }

    static lowerReceiver(value) {
        // This works exactly the same as lower for non-trait interfaces
        return this.lower(value);
    }

    static read(dataStream) {
        return this.lift(dataStream.readPointer(13));
    }

    static write(dataStream, value) {
        dataStream.writePointer(13, this.lower(value));
    }

    static computeSize(value) {
        return 8;
    }
}



