"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubtitleServiceClient = exports.SubtitleServiceService = exports.DeleteSubtitleMetadata = exports.DeleteSubtitleRequest = exports.GenerateSubtitleUploadURLResponse = exports.GenerateSubtitleUploadURLRequest = exports.CreateSubtitleMetadata = exports.SubtitleUploadParams = exports.CreateSubtitleRequest = exports.ListSubtitlesResponse = exports.ListSubtitlesRequest = exports.GetSubtitleRequest = 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 subtitle_1 = require("../../../../yandex/cloud/video/v1/subtitle");
const operation_1 = require("../../../../yandex/cloud/operation/operation");
exports.protobufPackage = 'yandex.cloud.video.v1';
const baseGetSubtitleRequest = { subtitleId: '' };
exports.GetSubtitleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.subtitleId !== '') {
            writer.uint32(10).string(message.subtitleId);
        }
        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({}, baseGetSubtitleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetSubtitleRequest);
        message.subtitleId =
            object.subtitleId !== undefined && object.subtitleId !== null
                ? String(object.subtitleId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.subtitleId !== undefined && (obj.subtitleId = message.subtitleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetSubtitleRequest);
        message.subtitleId = (_a = object.subtitleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseListSubtitlesRequest = { pageSize: 0, pageToken: '' };
exports.ListSubtitlesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.pageSize !== 0) {
            writer.uint32(800).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(810).string(message.pageToken);
        }
        if (message.videoId !== undefined) {
            writer.uint32(8002).string(message.videoId);
        }
        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({}, baseListSubtitlesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 100:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 101:
                    message.pageToken = reader.string();
                    break;
                case 1000:
                    message.videoId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListSubtitlesRequest);
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        message.videoId =
            object.videoId !== undefined && object.videoId !== null
                ? String(object.videoId)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        message.videoId !== undefined && (obj.videoId = message.videoId);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseListSubtitlesRequest);
        message.pageSize = (_a = object.pageSize) !== null && _a !== void 0 ? _a : 0;
        message.pageToken = (_b = object.pageToken) !== null && _b !== void 0 ? _b : '';
        message.videoId = (_c = object.videoId) !== null && _c !== void 0 ? _c : undefined;
        return message;
    },
};
const baseListSubtitlesResponse = { nextPageToken: '' };
exports.ListSubtitlesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.subtitles) {
            subtitle_1.Subtitle.encode(v, writer.uint32(10).fork()).ldelim();
        }
        if (message.nextPageToken !== '') {
            writer.uint32(802).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({}, baseListSubtitlesResponse);
        message.subtitles = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitles.push(subtitle_1.Subtitle.decode(reader, reader.uint32()));
                    break;
                case 100:
                    message.nextPageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListSubtitlesResponse);
        message.subtitles = ((_a = object.subtitles) !== null && _a !== void 0 ? _a : []).map((e) => subtitle_1.Subtitle.fromJSON(e));
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.subtitles) {
            obj.subtitles = message.subtitles.map((e) => (e ? subtitle_1.Subtitle.toJSON(e) : undefined));
        }
        else {
            obj.subtitles = [];
        }
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListSubtitlesResponse);
        message.subtitles = ((_a = object.subtitles) === null || _a === void 0 ? void 0 : _a.map((e) => subtitle_1.Subtitle.fromPartial(e))) || [];
        message.nextPageToken = (_b = object.nextPageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseCreateSubtitleRequest = { language: '', label: '' };
exports.CreateSubtitleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.language !== '') {
            writer.uint32(10).string(message.language);
        }
        if (message.label !== '') {
            writer.uint32(18).string(message.label);
        }
        if (message.videoId !== undefined) {
            writer.uint32(8002).string(message.videoId);
        }
        if (message.upload !== undefined) {
            exports.SubtitleUploadParams.encode(message.upload, writer.uint32(8802).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({}, baseCreateSubtitleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.language = reader.string();
                    break;
                case 2:
                    message.label = reader.string();
                    break;
                case 1000:
                    message.videoId = reader.string();
                    break;
                case 1100:
                    message.upload = exports.SubtitleUploadParams.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateSubtitleRequest);
        message.language =
            object.language !== undefined && object.language !== null
                ? String(object.language)
                : '';
        message.label =
            object.label !== undefined && object.label !== null ? String(object.label) : '';
        message.videoId =
            object.videoId !== undefined && object.videoId !== null
                ? String(object.videoId)
                : undefined;
        message.upload =
            object.upload !== undefined && object.upload !== null
                ? exports.SubtitleUploadParams.fromJSON(object.upload)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.language !== undefined && (obj.language = message.language);
        message.label !== undefined && (obj.label = message.label);
        message.videoId !== undefined && (obj.videoId = message.videoId);
        message.upload !== undefined &&
            (obj.upload = message.upload ? exports.SubtitleUploadParams.toJSON(message.upload) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c;
        const message = Object.assign({}, baseCreateSubtitleRequest);
        message.language = (_a = object.language) !== null && _a !== void 0 ? _a : '';
        message.label = (_b = object.label) !== null && _b !== void 0 ? _b : '';
        message.videoId = (_c = object.videoId) !== null && _c !== void 0 ? _c : undefined;
        message.upload =
            object.upload !== undefined && object.upload !== null
                ? exports.SubtitleUploadParams.fromPartial(object.upload)
                : undefined;
        return message;
    },
};
const baseSubtitleUploadParams = { filename: '' };
exports.SubtitleUploadParams = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.filename !== '') {
            writer.uint32(10).string(message.filename);
        }
        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({}, baseSubtitleUploadParams);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.filename = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseSubtitleUploadParams);
        message.filename =
            object.filename !== undefined && object.filename !== null
                ? String(object.filename)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.filename !== undefined && (obj.filename = message.filename);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseSubtitleUploadParams);
        message.filename = (_a = object.filename) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseCreateSubtitleMetadata = { subtitleId: '' };
exports.CreateSubtitleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.subtitleId !== '') {
            writer.uint32(10).string(message.subtitleId);
        }
        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({}, baseCreateSubtitleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseCreateSubtitleMetadata);
        message.subtitleId =
            object.subtitleId !== undefined && object.subtitleId !== null
                ? String(object.subtitleId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.subtitleId !== undefined && (obj.subtitleId = message.subtitleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseCreateSubtitleMetadata);
        message.subtitleId = (_a = object.subtitleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseGenerateSubtitleUploadURLRequest = { subtitleId: '' };
exports.GenerateSubtitleUploadURLRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.subtitleId !== '') {
            writer.uint32(10).string(message.subtitleId);
        }
        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({}, baseGenerateSubtitleUploadURLRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGenerateSubtitleUploadURLRequest);
        message.subtitleId =
            object.subtitleId !== undefined && object.subtitleId !== null
                ? String(object.subtitleId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.subtitleId !== undefined && (obj.subtitleId = message.subtitleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGenerateSubtitleUploadURLRequest);
        message.subtitleId = (_a = object.subtitleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseGenerateSubtitleUploadURLResponse = { uploadUrl: '' };
exports.GenerateSubtitleUploadURLResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.uploadUrl !== '') {
            writer.uint32(10).string(message.uploadUrl);
        }
        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({}, baseGenerateSubtitleUploadURLResponse);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.uploadUrl = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGenerateSubtitleUploadURLResponse);
        message.uploadUrl =
            object.uploadUrl !== undefined && object.uploadUrl !== null
                ? String(object.uploadUrl)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.uploadUrl !== undefined && (obj.uploadUrl = message.uploadUrl);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGenerateSubtitleUploadURLResponse);
        message.uploadUrl = (_a = object.uploadUrl) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDeleteSubtitleRequest = { subtitleId: '' };
exports.DeleteSubtitleRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.subtitleId !== '') {
            writer.uint32(10).string(message.subtitleId);
        }
        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({}, baseDeleteSubtitleRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteSubtitleRequest);
        message.subtitleId =
            object.subtitleId !== undefined && object.subtitleId !== null
                ? String(object.subtitleId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.subtitleId !== undefined && (obj.subtitleId = message.subtitleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDeleteSubtitleRequest);
        message.subtitleId = (_a = object.subtitleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
const baseDeleteSubtitleMetadata = { subtitleId: '' };
exports.DeleteSubtitleMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.subtitleId !== '') {
            writer.uint32(10).string(message.subtitleId);
        }
        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({}, baseDeleteSubtitleMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.subtitleId = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDeleteSubtitleMetadata);
        message.subtitleId =
            object.subtitleId !== undefined && object.subtitleId !== null
                ? String(object.subtitleId)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.subtitleId !== undefined && (obj.subtitleId = message.subtitleId);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDeleteSubtitleMetadata);
        message.subtitleId = (_a = object.subtitleId) !== null && _a !== void 0 ? _a : '';
        return message;
    },
};
/** Subtitle management service. */
exports.SubtitleServiceService = {
    /** Get a specific subtitle. */
    get: {
        path: '/yandex.cloud.video.v1.SubtitleService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetSubtitleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetSubtitleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(subtitle_1.Subtitle.encode(value).finish()),
        responseDeserialize: (value) => subtitle_1.Subtitle.decode(value),
    },
    /** List subtitles. */
    list: {
        path: '/yandex.cloud.video.v1.SubtitleService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListSubtitlesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListSubtitlesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListSubtitlesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListSubtitlesResponse.decode(value),
    },
    /** Create a new subtitle. */
    create: {
        path: '/yandex.cloud.video.v1.SubtitleService/Create',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.CreateSubtitleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.CreateSubtitleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Generate an upload URL to add a new subtitle file. */
    generateUploadURL: {
        path: '/yandex.cloud.video.v1.SubtitleService/GenerateUploadURL',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GenerateSubtitleUploadURLRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GenerateSubtitleUploadURLRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.GenerateSubtitleUploadURLResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.GenerateSubtitleUploadURLResponse.decode(value),
    },
    /** Delete a specific subtitle. */
    delete: {
        path: '/yandex.cloud.video.v1.SubtitleService/Delete',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DeleteSubtitleRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DeleteSubtitleRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
};
exports.SubtitleServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.SubtitleServiceService, 'yandex.cloud.video.v1.SubtitleService');
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();
}
