"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageGenerationAsyncServiceClient = exports.ImageGenerationAsyncServiceService = exports.ImageGenerationResponse = exports.ImageGenerationRequest = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const grpc_js_1 = require("@grpc/grpc-js");
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const image_generation_1 = require("../../../../../../yandex/cloud/ai/foundation_models/v1/image_generation/image_generation");
const operation_1 = require("../../../../../../yandex/cloud/operation/operation");
exports.protobufPackage = 'yandex.cloud.ai.foundation_models.v1.image_generation';
const baseImageGenerationRequest = { modelUri: '' };
exports.ImageGenerationRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.modelUri !== '') {
            writer.uint32(10).string(message.modelUri);
        }
        for (const v of message.messages) {
            image_generation_1.Message.encode(v, writer.uint32(18).fork()).ldelim();
        }
        if (message.generationOptions !== undefined) {
            image_generation_1.ImageGenerationOptions.encode(message.generationOptions, writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseImageGenerationRequest);
        message.messages = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.modelUri = reader.string();
                    break;
                case 2:
                    message.messages.push(image_generation_1.Message.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.generationOptions = image_generation_1.ImageGenerationOptions.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseImageGenerationRequest);
        message.modelUri =
            object.modelUri !== undefined && object.modelUri !== null
                ? String(object.modelUri)
                : '';
        message.messages = ((_a = object.messages) !== null && _a !== void 0 ? _a : []).map((e) => image_generation_1.Message.fromJSON(e));
        message.generationOptions =
            object.generationOptions !== undefined && object.generationOptions !== null
                ? image_generation_1.ImageGenerationOptions.fromJSON(object.generationOptions)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.modelUri !== undefined && (obj.modelUri = message.modelUri);
        if (message.messages) {
            obj.messages = message.messages.map((e) => (e ? image_generation_1.Message.toJSON(e) : undefined));
        }
        else {
            obj.messages = [];
        }
        message.generationOptions !== undefined &&
            (obj.generationOptions = message.generationOptions
                ? image_generation_1.ImageGenerationOptions.toJSON(message.generationOptions)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseImageGenerationRequest);
        message.modelUri = (_a = object.modelUri) !== null && _a !== void 0 ? _a : '';
        message.messages = ((_b = object.messages) === null || _b === void 0 ? void 0 : _b.map((e) => image_generation_1.Message.fromPartial(e))) || [];
        message.generationOptions =
            object.generationOptions !== undefined && object.generationOptions !== null
                ? image_generation_1.ImageGenerationOptions.fromPartial(object.generationOptions)
                : undefined;
        return message;
    },
};
const baseImageGenerationResponse = { modelVersion: '' };
exports.ImageGenerationResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.image.length !== 0) {
            writer.uint32(10).bytes(message.image);
        }
        if (message.modelVersion !== '') {
            writer.uint32(18).string(message.modelVersion);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof minimal_1.default.Reader ? input : new minimal_1.default.Reader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = Object.assign({}, baseImageGenerationResponse);
        message.image = Buffer.alloc(0);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.image = reader.bytes();
                    break;
                case 2:
                    message.modelVersion = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseImageGenerationResponse);
        message.image =
            object.image !== undefined && object.image !== null
                ? Buffer.from(bytesFromBase64(object.image))
                : Buffer.alloc(0);
        message.modelVersion =
            object.modelVersion !== undefined && object.modelVersion !== null
                ? String(object.modelVersion)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.image !== undefined &&
            (obj.image = base64FromBytes(message.image !== undefined ? message.image : Buffer.alloc(0)));
        message.modelVersion !== undefined && (obj.modelVersion = message.modelVersion);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseImageGenerationResponse);
        message.image = (_a = object.image) !== null && _a !== void 0 ? _a : Buffer.alloc(0);
        message.modelVersion = (_b = object.modelVersion) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
/** Service for creating images based on a text description. */
exports.ImageGenerationAsyncServiceService = {
    /** A method for generating an image based on a textual description. */
    generate: {
        path: '/yandex.cloud.ai.foundation_models.v1.image_generation.ImageGenerationAsyncService/Generate',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ImageGenerationRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ImageGenerationRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
};
exports.ImageGenerationAsyncServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.ImageGenerationAsyncServiceService, 'yandex.cloud.ai.foundation_models.v1.image_generation.ImageGenerationAsyncService');
var globalThis = (() => {
    if (typeof globalThis !== 'undefined')
        return globalThis;
    if (typeof self !== 'undefined')
        return self;
    if (typeof window !== 'undefined')
        return window;
    if (typeof global !== 'undefined')
        return global;
    throw 'Unable to locate global object';
})();
const atob = globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
function bytesFromBase64(b64) {
    const bin = atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
        arr[i] = bin.charCodeAt(i);
    }
    return arr;
}
const btoa = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr) {
    const bin = [];
    for (const byte of arr) {
        bin.push(String.fromCharCode(byte));
    }
    return btoa(bin.join(''));
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
