"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TalkServiceClient = exports.TalkServiceService = exports.GetTalkResponse = exports.GetTalkRequest = exports.SearchTalkResponse = exports.SearchTalkRequest = exports.UserMetadata_FieldsEntry = exports.UserMetadata = exports.TalkMetadata_FieldsEntry = exports.TalkMetadata = exports.UploadTextResponse = exports.UploadTextRequest = exports.UploadTalkResponse = exports.UploadTalkRequest = exports.StreamTalkRequest = exports.userRoleToJSON = exports.userRoleFromJSON = exports.UserRole = 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 audio_1 = require("../../../../yandex/cloud/speechsense/v1/audio");
const text_1 = require("../../../../yandex/cloud/speechsense/v1/text");
const search_1 = require("../../../../yandex/cloud/speechsense/v1/search");
const field_mask_1 = require("../../../../google/protobuf/field_mask");
const talk_1 = require("../../../../yandex/cloud/speechsense/v1/talk");
exports.protobufPackage = 'yandex.cloud.speechsense.v1';
var UserRole;
(function (UserRole) {
    UserRole[UserRole["USER_ROLE_UNSPECIFIED"] = 0] = "USER_ROLE_UNSPECIFIED";
    UserRole[UserRole["USER_ROLE_OPERATOR"] = 1] = "USER_ROLE_OPERATOR";
    UserRole[UserRole["USER_ROLE_CLIENT"] = 2] = "USER_ROLE_CLIENT";
    UserRole[UserRole["USER_ROLE_BOT"] = 3] = "USER_ROLE_BOT";
    UserRole[UserRole["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(UserRole = exports.UserRole || (exports.UserRole = {}));
function userRoleFromJSON(object) {
    switch (object) {
        case 0:
        case 'USER_ROLE_UNSPECIFIED':
            return UserRole.USER_ROLE_UNSPECIFIED;
        case 1:
        case 'USER_ROLE_OPERATOR':
            return UserRole.USER_ROLE_OPERATOR;
        case 2:
        case 'USER_ROLE_CLIENT':
            return UserRole.USER_ROLE_CLIENT;
        case 3:
        case 'USER_ROLE_BOT':
            return UserRole.USER_ROLE_BOT;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return UserRole.UNRECOGNIZED;
    }
}
exports.userRoleFromJSON = userRoleFromJSON;
function userRoleToJSON(object) {
    switch (object) {
        case UserRole.USER_ROLE_UNSPECIFIED:
            return 'USER_ROLE_UNSPECIFIED';
        case UserRole.USER_ROLE_OPERATOR:
            return 'USER_ROLE_OPERATOR';
        case UserRole.USER_ROLE_CLIENT:
            return 'USER_ROLE_CLIENT';
        case UserRole.USER_ROLE_BOT:
            return 'USER_ROLE_BOT';
        default:
            return 'UNKNOWN';
    }
}
exports.userRoleToJSON = userRoleToJSON;
const baseStreamTalkRequest = {};
exports.StreamTalkRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.metadata !== undefined) {
            exports.TalkMetadata.encode(message.metadata, writer.uint32(10).fork()).ldelim();
        }
        if (message.audio !== undefined) {
            audio_1.AudioStreamingRequest.encode(message.audio, writer.uint32(18).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({}, baseStreamTalkRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.metadata = exports.TalkMetadata.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.audio = audio_1.AudioStreamingRequest.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseStreamTalkRequest);
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromJSON(object.metadata)
                : undefined;
        message.audio =
            object.audio !== undefined && object.audio !== null
                ? audio_1.AudioStreamingRequest.fromJSON(object.audio)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.metadata !== undefined &&
            (obj.metadata = message.metadata ? exports.TalkMetadata.toJSON(message.metadata) : undefined);
        message.audio !== undefined &&
            (obj.audio = message.audio ? audio_1.AudioStreamingRequest.toJSON(message.audio) : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = Object.assign({}, baseStreamTalkRequest);
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromPartial(object.metadata)
                : undefined;
        message.audio =
            object.audio !== undefined && object.audio !== null
                ? audio_1.AudioStreamingRequest.fromPartial(object.audio)
                : undefined;
        return message;
    },
};
const baseUploadTalkRequest = { talkId: '' };
exports.UploadTalkRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.talkId !== '') {
            writer.uint32(26).string(message.talkId);
        }
        if (message.metadata !== undefined) {
            exports.TalkMetadata.encode(message.metadata, writer.uint32(10).fork()).ldelim();
        }
        if (message.audio !== undefined) {
            audio_1.AudioRequest.encode(message.audio, writer.uint32(18).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({}, baseUploadTalkRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.talkId = reader.string();
                    break;
                case 1:
                    message.metadata = exports.TalkMetadata.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.audio = audio_1.AudioRequest.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUploadTalkRequest);
        message.talkId =
            object.talkId !== undefined && object.talkId !== null ? String(object.talkId) : '';
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromJSON(object.metadata)
                : undefined;
        message.audio =
            object.audio !== undefined && object.audio !== null
                ? audio_1.AudioRequest.fromJSON(object.audio)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.talkId !== undefined && (obj.talkId = message.talkId);
        message.metadata !== undefined &&
            (obj.metadata = message.metadata ? exports.TalkMetadata.toJSON(message.metadata) : undefined);
        message.audio !== undefined &&
            (obj.audio = message.audio ? audio_1.AudioRequest.toJSON(message.audio) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUploadTalkRequest);
        message.talkId = (_a = object.talkId) !== null && _a !== void 0 ? _a : '';
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromPartial(object.metadata)
                : undefined;
        message.audio =
            object.audio !== undefined && object.audio !== null
                ? audio_1.AudioRequest.fromPartial(object.audio)
                : undefined;
        return message;
    },
};
const baseUploadTalkResponse = { talkId: '' };
exports.UploadTalkResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.talkId !== '') {
            writer.uint32(10).string(message.talkId);
        }
        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({}, baseUploadTalkResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.talkId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUploadTalkResponse);
        message.talkId =
            object.talkId !== undefined && object.talkId !== null ? String(object.talkId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.talkId !== undefined && (obj.talkId = message.talkId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUploadTalkResponse);
        message.talkId = (_a = object.talkId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseUploadTextRequest = { talkId: '' };
exports.UploadTextRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.talkId !== '') {
            writer.uint32(26).string(message.talkId);
        }
        if (message.metadata !== undefined) {
            exports.TalkMetadata.encode(message.metadata, writer.uint32(10).fork()).ldelim();
        }
        if (message.textContent !== undefined) {
            text_1.TextContent.encode(message.textContent, writer.uint32(18).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({}, baseUploadTextRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 3:
                    message.talkId = reader.string();
                    break;
                case 1:
                    message.metadata = exports.TalkMetadata.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.textContent = text_1.TextContent.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUploadTextRequest);
        message.talkId =
            object.talkId !== undefined && object.talkId !== null ? String(object.talkId) : '';
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromJSON(object.metadata)
                : undefined;
        message.textContent =
            object.textContent !== undefined && object.textContent !== null
                ? text_1.TextContent.fromJSON(object.textContent)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.talkId !== undefined && (obj.talkId = message.talkId);
        message.metadata !== undefined &&
            (obj.metadata = message.metadata ? exports.TalkMetadata.toJSON(message.metadata) : undefined);
        message.textContent !== undefined &&
            (obj.textContent = message.textContent
                ? text_1.TextContent.toJSON(message.textContent)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUploadTextRequest);
        message.talkId = (_a = object.talkId) !== null && _a !== void 0 ? _a : '';
        message.metadata =
            object.metadata !== undefined && object.metadata !== null
                ? exports.TalkMetadata.fromPartial(object.metadata)
                : undefined;
        message.textContent =
            object.textContent !== undefined && object.textContent !== null
                ? text_1.TextContent.fromPartial(object.textContent)
                : undefined;
        return message;
    },
};
const baseUploadTextResponse = { talkId: '' };
exports.UploadTextResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.talkId !== '') {
            writer.uint32(10).string(message.talkId);
        }
        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({}, baseUploadTextResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.talkId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUploadTextResponse);
        message.talkId =
            object.talkId !== undefined && object.talkId !== null ? String(object.talkId) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.talkId !== undefined && (obj.talkId = message.talkId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseUploadTextResponse);
        message.talkId = (_a = object.talkId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseTalkMetadata = { connectionId: '' };
exports.TalkMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.connectionId !== '') {
            writer.uint32(10).string(message.connectionId);
        }
        Object.entries(message.fields).forEach(([key, value]) => {
            exports.TalkMetadata_FieldsEntry.encode({ key: key, value }, writer.uint32(18).fork()).ldelim();
        });
        for (const v of message.users) {
            exports.UserMetadata.encode(v, 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({}, baseTalkMetadata);
        message.fields = {};
        message.users = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.connectionId = reader.string();
                    break;
                case 2:
                    const entry2 = exports.TalkMetadata_FieldsEntry.decode(reader, reader.uint32());
                    if (entry2.value !== undefined) {
                        message.fields[entry2.key] = entry2.value;
                    }
                    break;
                case 3:
                    message.users.push(exports.UserMetadata.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a, _b;
        const message = Object.assign({}, baseTalkMetadata);
        message.connectionId =
            object.connectionId !== undefined && object.connectionId !== null
                ? String(object.connectionId)
                : '';
        message.fields = Object.entries((_a = object.fields) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        message.users = ((_b = object.users) !== null && _b !== void 0 ? _b : []).map((e) => exports.UserMetadata.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.connectionId !== undefined && (obj.connectionId = message.connectionId);
        obj.fields = {};
        if (message.fields) {
            Object.entries(message.fields).forEach(([k, v]) => {
                obj.fields[k] = v;
            });
        }
        if (message.users) {
            obj.users = message.users.map((e) => (e ? exports.UserMetadata.toJSON(e) : undefined));
        }
        else {
            obj.users = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseTalkMetadata);
        message.connectionId = (_a = object.connectionId) !== null && _a !== void 0 ? _a : '';
        message.fields = Object.entries((_b = object.fields) !== null && _b !== void 0 ? _b : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        message.users = ((_c = object.users) === null || _c === void 0 ? void 0 : _c.map((e) => exports.UserMetadata.fromPartial(e))) || [];
        return message;
    },
};
const baseTalkMetadata_FieldsEntry = { key: '', value: '' };
exports.TalkMetadata_FieldsEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== '') {
            writer.uint32(10).string(message.key);
        }
        if (message.value !== '') {
            writer.uint32(18).string(message.value);
        }
        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({}, baseTalkMetadata_FieldsEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.value = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseTalkMetadata_FieldsEntry);
        message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
        message.value =
            object.value !== undefined && object.value !== null ? String(object.value) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = message.key);
        message.value !== undefined && (obj.value = message.value);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseTalkMetadata_FieldsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseUserMetadata = { id: '', role: 0 };
exports.UserMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.role !== 0) {
            writer.uint32(16).int32(message.role);
        }
        Object.entries(message.fields).forEach(([key, value]) => {
            exports.UserMetadata_FieldsEntry.encode({ key: key, value }, 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({}, baseUserMetadata);
        message.fields = {};
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.role = reader.int32();
                    break;
                case 3:
                    const entry3 = exports.UserMetadata_FieldsEntry.decode(reader, reader.uint32());
                    if (entry3.value !== undefined) {
                        message.fields[entry3.key] = entry3.value;
                    }
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseUserMetadata);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.role =
            object.role !== undefined && object.role !== null ? userRoleFromJSON(object.role) : 0;
        message.fields = Object.entries((_a = object.fields) !== null && _a !== void 0 ? _a : {}).reduce((acc, [key, value]) => {
            acc[key] = String(value);
            return acc;
        }, {});
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.role !== undefined && (obj.role = userRoleToJSON(message.role));
        obj.fields = {};
        if (message.fields) {
            Object.entries(message.fields).forEach(([k, v]) => {
                obj.fields[k] = v;
            });
        }
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseUserMetadata);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.role = (_b = object.role) !== null && _b !== void 0 ? _b : 0;
        message.fields = Object.entries((_c = object.fields) !== null && _c !== void 0 ? _c : {}).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = String(value);
            }
            return acc;
        }, {});
        return message;
    },
};
const baseUserMetadata_FieldsEntry = { key: '', value: '' };
exports.UserMetadata_FieldsEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.key !== '') {
            writer.uint32(10).string(message.key);
        }
        if (message.value !== '') {
            writer.uint32(18).string(message.value);
        }
        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({}, baseUserMetadata_FieldsEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.key = reader.string();
                    break;
                case 2:
                    message.value = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseUserMetadata_FieldsEntry);
        message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
        message.value =
            object.value !== undefined && object.value !== null ? String(object.value) : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.key !== undefined && (obj.key = message.key);
        message.value !== undefined && (obj.value = message.value);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseUserMetadata_FieldsEntry);
        message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
        message.value = (_b = object.value) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseSearchTalkRequest = {
    organizationId: '',
    spaceId: '',
    connectionId: '',
    projectId: '',
    pageSize: 0,
    pageToken: '',
};
exports.SearchTalkRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.organizationId !== '') {
            writer.uint32(10).string(message.organizationId);
        }
        if (message.spaceId !== '') {
            writer.uint32(18).string(message.spaceId);
        }
        if (message.connectionId !== '') {
            writer.uint32(26).string(message.connectionId);
        }
        if (message.projectId !== '') {
            writer.uint32(34).string(message.projectId);
        }
        for (const v of message.filters) {
            search_1.Filter.encode(v, writer.uint32(42).fork()).ldelim();
        }
        if (message.query !== undefined) {
            search_1.Query.encode(message.query, writer.uint32(50).fork()).ldelim();
        }
        if (message.pageSize !== 0) {
            writer.uint32(56).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(66).string(message.pageToken);
        }
        if (message.sortData !== undefined) {
            search_1.SortData.encode(message.sortData, writer.uint32(74).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({}, baseSearchTalkRequest);
        message.filters = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.organizationId = reader.string();
                    break;
                case 2:
                    message.spaceId = reader.string();
                    break;
                case 3:
                    message.connectionId = reader.string();
                    break;
                case 4:
                    message.projectId = reader.string();
                    break;
                case 5:
                    message.filters.push(search_1.Filter.decode(reader, reader.uint32()));
                    break;
                case 6:
                    message.query = search_1.Query.decode(reader, reader.uint32());
                    break;
                case 7:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 8:
                    message.pageToken = reader.string();
                    break;
                case 9:
                    message.sortData = search_1.SortData.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseSearchTalkRequest);
        message.organizationId =
            object.organizationId !== undefined && object.organizationId !== null
                ? String(object.organizationId)
                : '';
        message.spaceId =
            object.spaceId !== undefined && object.spaceId !== null ? String(object.spaceId) : '';
        message.connectionId =
            object.connectionId !== undefined && object.connectionId !== null
                ? String(object.connectionId)
                : '';
        message.projectId =
            object.projectId !== undefined && object.projectId !== null
                ? String(object.projectId)
                : '';
        message.filters = ((_a = object.filters) !== null && _a !== void 0 ? _a : []).map((e) => search_1.Filter.fromJSON(e));
        message.query =
            object.query !== undefined && object.query !== null
                ? search_1.Query.fromJSON(object.query)
                : undefined;
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        message.sortData =
            object.sortData !== undefined && object.sortData !== null
                ? search_1.SortData.fromJSON(object.sortData)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.organizationId !== undefined && (obj.organizationId = message.organizationId);
        message.spaceId !== undefined && (obj.spaceId = message.spaceId);
        message.connectionId !== undefined && (obj.connectionId = message.connectionId);
        message.projectId !== undefined && (obj.projectId = message.projectId);
        if (message.filters) {
            obj.filters = message.filters.map((e) => (e ? search_1.Filter.toJSON(e) : undefined));
        }
        else {
            obj.filters = [];
        }
        message.query !== undefined &&
            (obj.query = message.query ? search_1.Query.toJSON(message.query) : undefined);
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        message.sortData !== undefined &&
            (obj.sortData = message.sortData ? search_1.SortData.toJSON(message.sortData) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, baseSearchTalkRequest);
        message.organizationId = (_a = object.organizationId) !== null && _a !== void 0 ? _a : '';
        message.spaceId = (_b = object.spaceId) !== null && _b !== void 0 ? _b : '';
        message.connectionId = (_c = object.connectionId) !== null && _c !== void 0 ? _c : '';
        message.projectId = (_d = object.projectId) !== null && _d !== void 0 ? _d : '';
        message.filters = ((_e = object.filters) === null || _e === void 0 ? void 0 : _e.map((e) => search_1.Filter.fromPartial(e))) || [];
        message.query =
            object.query !== undefined && object.query !== null
                ? search_1.Query.fromPartial(object.query)
                : undefined;
        message.pageSize = (_f = object.pageSize) !== null && _f !== void 0 ? _f : 0;
        message.pageToken = (_g = object.pageToken) !== null && _g !== void 0 ? _g : '';
        message.sortData =
            object.sortData !== undefined && object.sortData !== null
                ? search_1.SortData.fromPartial(object.sortData)
                : undefined;
        return message;
    },
};
const baseSearchTalkResponse = { talkIds: '', talksCount: 0, nextPageToken: '' };
exports.SearchTalkResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.talkIds) {
            writer.uint32(10).string(v);
        }
        if (message.talksCount !== 0) {
            writer.uint32(16).int64(message.talksCount);
        }
        if (message.nextPageToken !== '') {
            writer.uint32(26).string(message.nextPageToken);
        }
        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({}, baseSearchTalkResponse);
        message.talkIds = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.talkIds.push(reader.string());
                    break;
                case 2:
                    message.talksCount = longToNumber(reader.int64());
                    break;
                case 3:
                    message.nextPageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseSearchTalkResponse);
        message.talkIds = ((_a = object.talkIds) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        message.talksCount =
            object.talksCount !== undefined && object.talksCount !== null
                ? Number(object.talksCount)
                : 0;
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.talkIds) {
            obj.talkIds = message.talkIds.map((e) => e);
        }
        else {
            obj.talkIds = [];
        }
        message.talksCount !== undefined && (obj.talksCount = Math.round(message.talksCount));
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseSearchTalkResponse);
        message.talkIds = ((_a = object.talkIds) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
        message.talksCount = (_b = object.talksCount) !== null && _b !== void 0 ? _b : 0;
        message.nextPageToken = (_c = object.nextPageToken) !== null && _c !== void 0 ? _c : '';
        return message;
    },
};
const baseGetTalkRequest = {
    organizationId: '',
    spaceId: '',
    connectionId: '',
    projectId: '',
    talkIds: '',
};
exports.GetTalkRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.organizationId !== '') {
            writer.uint32(10).string(message.organizationId);
        }
        if (message.spaceId !== '') {
            writer.uint32(18).string(message.spaceId);
        }
        if (message.connectionId !== '') {
            writer.uint32(26).string(message.connectionId);
        }
        if (message.projectId !== '') {
            writer.uint32(34).string(message.projectId);
        }
        for (const v of message.talkIds) {
            writer.uint32(42).string(v);
        }
        if (message.resultsMask !== undefined) {
            field_mask_1.FieldMask.encode(message.resultsMask, writer.uint32(50).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({}, baseGetTalkRequest);
        message.talkIds = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.organizationId = reader.string();
                    break;
                case 2:
                    message.spaceId = reader.string();
                    break;
                case 3:
                    message.connectionId = reader.string();
                    break;
                case 4:
                    message.projectId = reader.string();
                    break;
                case 5:
                    message.talkIds.push(reader.string());
                    break;
                case 6:
                    message.resultsMask = field_mask_1.FieldMask.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseGetTalkRequest);
        message.organizationId =
            object.organizationId !== undefined && object.organizationId !== null
                ? String(object.organizationId)
                : '';
        message.spaceId =
            object.spaceId !== undefined && object.spaceId !== null ? String(object.spaceId) : '';
        message.connectionId =
            object.connectionId !== undefined && object.connectionId !== null
                ? String(object.connectionId)
                : '';
        message.projectId =
            object.projectId !== undefined && object.projectId !== null
                ? String(object.projectId)
                : '';
        message.talkIds = ((_a = object.talkIds) !== null && _a !== void 0 ? _a : []).map((e) => String(e));
        message.resultsMask =
            object.resultsMask !== undefined && object.resultsMask !== null
                ? field_mask_1.FieldMask.fromJSON(object.resultsMask)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.organizationId !== undefined && (obj.organizationId = message.organizationId);
        message.spaceId !== undefined && (obj.spaceId = message.spaceId);
        message.connectionId !== undefined && (obj.connectionId = message.connectionId);
        message.projectId !== undefined && (obj.projectId = message.projectId);
        if (message.talkIds) {
            obj.talkIds = message.talkIds.map((e) => e);
        }
        else {
            obj.talkIds = [];
        }
        message.resultsMask !== undefined &&
            (obj.resultsMask = message.resultsMask
                ? field_mask_1.FieldMask.toJSON(message.resultsMask)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e;
        const message = Object.assign({}, baseGetTalkRequest);
        message.organizationId = (_a = object.organizationId) !== null && _a !== void 0 ? _a : '';
        message.spaceId = (_b = object.spaceId) !== null && _b !== void 0 ? _b : '';
        message.connectionId = (_c = object.connectionId) !== null && _c !== void 0 ? _c : '';
        message.projectId = (_d = object.projectId) !== null && _d !== void 0 ? _d : '';
        message.talkIds = ((_e = object.talkIds) === null || _e === void 0 ? void 0 : _e.map((e) => e)) || [];
        message.resultsMask =
            object.resultsMask !== undefined && object.resultsMask !== null
                ? field_mask_1.FieldMask.fromPartial(object.resultsMask)
                : undefined;
        return message;
    },
};
const baseGetTalkResponse = {};
exports.GetTalkResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.talk) {
            talk_1.Talk.encode(v, writer.uint32(10).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({}, baseGetTalkResponse);
        message.talk = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.talk.push(talk_1.Talk.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseGetTalkResponse);
        message.talk = ((_a = object.talk) !== null && _a !== void 0 ? _a : []).map((e) => talk_1.Talk.fromJSON(e));
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.talk) {
            obj.talk = message.talk.map((e) => (e ? talk_1.Talk.toJSON(e) : undefined));
        }
        else {
            obj.talk = [];
        }
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetTalkResponse);
        message.talk = ((_a = object.talk) === null || _a === void 0 ? void 0 : _a.map((e) => talk_1.Talk.fromPartial(e))) || [];
        return message;
    },
};
exports.TalkServiceService = {
    /**
     * rpc for streaming talk documents. First message should contain Talk related metadata,
     * second - audio metadata, others should contain audio bytes in chunks
     */
    uploadAsStream: {
        path: '/yandex.cloud.speechsense.v1.TalkService/UploadAsStream',
        requestStream: true,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.StreamTalkRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.StreamTalkRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.UploadTalkResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.UploadTalkResponse.decode(value),
    },
    /** rpc for uploading talk document as single message */
    upload: {
        path: '/yandex.cloud.speechsense.v1.TalkService/Upload',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.UploadTalkRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.UploadTalkRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.UploadTalkResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.UploadTalkResponse.decode(value),
    },
    /** rpc for uploading text talk document */
    uploadText: {
        path: '/yandex.cloud.speechsense.v1.TalkService/UploadText',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.UploadTextRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.UploadTextRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.UploadTextResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.UploadTextResponse.decode(value),
    },
    /** rpc for searching talks. will return ids only */
    search: {
        path: '/yandex.cloud.speechsense.v1.TalkService/Search',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.SearchTalkRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.SearchTalkRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.SearchTalkResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.SearchTalkResponse.decode(value),
    },
    /** rpc for bulk get */
    get: {
        path: '/yandex.cloud.speechsense.v1.TalkService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetTalkRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetTalkRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.GetTalkResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.GetTalkResponse.decode(value),
    },
};
exports.TalkServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.TalkServiceService, 'yandex.cloud.speechsense.v1.TalkService');
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';
})();
function longToNumber(long) {
    if (long.gt(Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
    }
    return long.toNumber();
}
if (minimal_1.default.util.Long !== long_1.default) {
    minimal_1.default.util.Long = long_1.default;
    minimal_1.default.configure();
}
