"use strict";
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.8
//   protoc               v4.25.9
// source: io/restorecommerce/file.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.protoMetadata = exports.FileList = exports.File = exports.protobufPackage = void 0;
/* eslint-disable */
const wire_1 = require("@bufbuild/protobuf/wire");
const image_1 = require("./image");
exports.protobufPackage = "io.restorecommerce.file";
function createBaseFile() {
    return {};
}
exports.File = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.id !== undefined) {
            writer.uint32(10).string(message.id);
        }
        if (message.ordinal !== undefined) {
            writer.uint32(16).uint32(message.ordinal);
        }
        if (message.caption !== undefined) {
            writer.uint32(26).string(message.caption);
        }
        if (message.filename !== undefined) {
            writer.uint32(34).string(message.filename);
        }
        if (message.contentType !== undefined) {
            writer.uint32(42).string(message.contentType);
        }
        if (message.url !== undefined) {
            writer.uint32(50).string(message.url);
        }
        if (message.base64 !== undefined) {
            writer.uint32(58).string(message.base64);
        }
        if (message.blob !== undefined) {
            writer.uint32(66).bytes(message.blob);
        }
        if (message.bytes !== undefined) {
            writer.uint32(72).int64(message.bytes);
        }
        if (message.tags !== undefined && message.tags.length !== 0) {
            for (const v of message.tags) {
                writer.uint32(82).string(v);
            }
        }
        if (message.thumbnail !== undefined) {
            image_1.Image.encode(message.thumbnail, writer.uint32(90).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseFile();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 16) {
                        break;
                    }
                    message.ordinal = reader.uint32();
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.caption = reader.string();
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    message.filename = reader.string();
                    continue;
                }
                case 5: {
                    if (tag !== 42) {
                        break;
                    }
                    message.contentType = reader.string();
                    continue;
                }
                case 6: {
                    if (tag !== 50) {
                        break;
                    }
                    message.url = reader.string();
                    continue;
                }
                case 7: {
                    if (tag !== 58) {
                        break;
                    }
                    message.base64 = reader.string();
                    continue;
                }
                case 8: {
                    if (tag !== 66) {
                        break;
                    }
                    message.blob = Buffer.from(reader.bytes());
                    continue;
                }
                case 9: {
                    if (tag !== 72) {
                        break;
                    }
                    message.bytes = longToNumber(reader.int64());
                    continue;
                }
                case 10: {
                    if (tag !== 82) {
                        break;
                    }
                    if (message.tags === undefined) {
                        message.tags = [];
                    }
                    const el = reader.string();
                    if (el !== undefined) {
                        message.tags.push(el);
                    }
                    continue;
                }
                case 11: {
                    if (tag !== 90) {
                        break;
                    }
                    message.thumbnail = image_1.Image.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
            ordinal: isSet(object.ordinal) ? globalThis.Number(object.ordinal) : undefined,
            caption: isSet(object.caption) ? globalThis.String(object.caption) : undefined,
            filename: isSet(object.filename) ? globalThis.String(object.filename) : undefined,
            contentType: isSet(object.contentType)
                ? globalThis.String(object.contentType)
                : isSet(object.content_type)
                    ? globalThis.String(object.content_type)
                    : undefined,
            url: isSet(object.url) ? globalThis.String(object.url) : undefined,
            base64: isSet(object.base64) ? globalThis.String(object.base64) : undefined,
            blob: isSet(object.blob) ? Buffer.from(bytesFromBase64(object.blob)) : undefined,
            bytes: isSet(object.bytes) ? globalThis.Number(object.bytes) : undefined,
            tags: globalThis.Array.isArray(object?.tags) ? object.tags.map((e) => globalThis.String(e)) : undefined,
            thumbnail: isSet(object.thumbnail) ? image_1.Image.fromJSON(object.thumbnail) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        if (message.ordinal !== undefined) {
            obj.ordinal = Math.round(message.ordinal);
        }
        if (message.caption !== undefined) {
            obj.caption = message.caption;
        }
        if (message.filename !== undefined) {
            obj.filename = message.filename;
        }
        if (message.contentType !== undefined) {
            obj.contentType = message.contentType;
        }
        if (message.url !== undefined) {
            obj.url = message.url;
        }
        if (message.base64 !== undefined) {
            obj.base64 = message.base64;
        }
        if (message.blob !== undefined) {
            obj.blob = base64FromBytes(message.blob);
        }
        if (message.bytes !== undefined) {
            obj.bytes = Math.round(message.bytes);
        }
        if (message.tags?.length) {
            obj.tags = message.tags;
        }
        if (message.thumbnail !== undefined) {
            obj.thumbnail = image_1.Image.toJSON(message.thumbnail);
        }
        return obj;
    },
    create(base) {
        return exports.File.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseFile();
        message.id = object.id ?? undefined;
        message.ordinal = object.ordinal ?? undefined;
        message.caption = object.caption ?? undefined;
        message.filename = object.filename ?? undefined;
        message.contentType = object.contentType ?? undefined;
        message.url = object.url ?? undefined;
        message.base64 = object.base64 ?? undefined;
        message.blob = object.blob ?? undefined;
        message.bytes = object.bytes ?? undefined;
        message.tags = object.tags?.map((e) => e) || undefined;
        message.thumbnail = (object.thumbnail !== undefined && object.thumbnail !== null)
            ? image_1.Image.fromPartial(object.thumbnail)
            : undefined;
        return message;
    },
};
function createBaseFileList() {
    return {};
}
exports.FileList = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.items !== undefined && message.items.length !== 0) {
            for (const v of message.items) {
                exports.File.encode(v, writer.uint32(10).fork()).join();
            }
        }
        if (message.totalCount !== undefined) {
            writer.uint32(16).uint32(message.totalCount);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseFileList();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    if (message.items === undefined) {
                        message.items = [];
                    }
                    const el = exports.File.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.items.push(el);
                    }
                    continue;
                }
                case 2: {
                    if (tag !== 16) {
                        break;
                    }
                    message.totalCount = reader.uint32();
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => exports.File.fromJSON(e)) : undefined,
            totalCount: isSet(object.totalCount)
                ? globalThis.Number(object.totalCount)
                : isSet(object.total_count)
                    ? globalThis.Number(object.total_count)
                    : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.items?.length) {
            obj.items = message.items.map((e) => exports.File.toJSON(e));
        }
        if (message.totalCount !== undefined) {
            obj.totalCount = Math.round(message.totalCount);
        }
        return obj;
    },
    create(base) {
        return exports.FileList.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseFileList();
        message.items = object.items?.map((e) => exports.File.fromPartial(e)) || undefined;
        message.totalCount = object.totalCount ?? undefined;
        return message;
    },
};
exports.protoMetadata = {
    fileDescriptor: {
        "name": "io/restorecommerce/file.proto",
        "package": "io.restorecommerce.file",
        "dependency": ["io/restorecommerce/image.proto"],
        "publicDependency": [],
        "weakDependency": [],
        "optionDependency": [],
        "messageType": [{
                "name": "File",
                "field": [{
                        "name": "id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "id",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "ordinal",
                        "number": 2,
                        "label": 1,
                        "type": 13,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "ordinal",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "caption",
                        "number": 3,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 3,
                        "jsonName": "caption",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "filename",
                        "number": 4,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 4,
                        "jsonName": "filename",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "content_type",
                        "number": 5,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 5,
                        "jsonName": "contentType",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "url",
                        "number": 6,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "url",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "base64",
                        "number": 7,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "base64",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "blob",
                        "number": 8,
                        "label": 1,
                        "type": 12,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "blob",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "bytes",
                        "number": 9,
                        "label": 1,
                        "type": 3,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 6,
                        "jsonName": "bytes",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "tags",
                        "number": 10,
                        "label": 3,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "tags",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "thumbnail",
                        "number": 11,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.image.Image",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 7,
                        "jsonName": "thumbnail",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [
                    { "name": "type", "options": undefined },
                    { "name": "_id", "options": undefined },
                    { "name": "_ordinal", "options": undefined },
                    { "name": "_caption", "options": undefined },
                    { "name": "_filename", "options": undefined },
                    { "name": "_content_type", "options": undefined },
                    { "name": "_bytes", "options": undefined },
                    { "name": "_thumbnail", "options": undefined },
                ],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "FileList",
                "field": [{
                        "name": "items",
                        "number": 1,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.file.File",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "items",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "total_count",
                        "number": 2,
                        "label": 1,
                        "type": 13,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "totalCount",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_total_count", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }],
        "enumType": [],
        "service": [],
        "extension": [],
        "options": undefined,
        "sourceCodeInfo": { "location": [] },
        "syntax": "proto3",
        "edition": 0,
    },
    references: { ".io.restorecommerce.file.File": exports.File, ".io.restorecommerce.file.FileList": exports.FileList },
    dependencies: [image_1.protoMetadata],
};
function bytesFromBase64(b64) {
    return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
}
function base64FromBytes(arr) {
    return globalThis.Buffer.from(arr).toString("base64");
}
function longToNumber(int64) {
    const num = globalThis.Number(int64.toString());
    if (num > globalThis.Number.MAX_SAFE_INTEGER) {
        throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
    }
    if (num < globalThis.Number.MIN_SAFE_INTEGER) {
        throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
    }
    return num;
}
function isSet(value) {
    return value !== null && value !== undefined;
}
//# sourceMappingURL=file.js.map