"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceControlServiceClient = exports.ServiceControlServiceService = exports.ResolveServiceAgentRequest = exports.DisableServiceMetadata = exports.DisableServiceRequest = exports.EnableServiceMetadata = exports.EnableServiceRequest = exports.ListServicesResponse = exports.ListServicesRequest = exports.GetServiceRequest = 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 resource_1 = require("../../../../yandex/cloud/iam/v1/resource");
const service_control_1 = require("../../../../yandex/cloud/iam/v1/service_control");
const operation_1 = require("../../../../yandex/cloud/operation/operation");
exports.protobufPackage = 'yandex.cloud.iam.v1';
const baseGetServiceRequest = { serviceId: '' };
exports.GetServiceRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseGetServiceRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseGetServiceRequest);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseGetServiceRequest);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
const baseListServicesRequest = { pageSize: 0, pageToken: '' };
exports.ListServicesRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, writer.uint32(10).fork()).ldelim();
        }
        if (message.pageSize !== 0) {
            writer.uint32(16).int64(message.pageSize);
        }
        if (message.pageToken !== '') {
            writer.uint32(26).string(message.pageToken);
        }
        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({}, baseListServicesRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.pageSize = longToNumber(reader.int64());
                    break;
                case 3:
                    message.pageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseListServicesRequest);
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        message.pageSize =
            object.pageSize !== undefined && object.pageSize !== null ? Number(object.pageSize) : 0;
        message.pageToken =
            object.pageToken !== undefined && object.pageToken !== null
                ? String(object.pageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        message.pageSize !== undefined && (obj.pageSize = Math.round(message.pageSize));
        message.pageToken !== undefined && (obj.pageToken = message.pageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListServicesRequest);
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        message.pageSize = (_a = object.pageSize) !== null && _a !== void 0 ? _a : 0;
        message.pageToken = (_b = object.pageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseListServicesResponse = { nextPageToken: '' };
exports.ListServicesResponse = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        for (const v of message.services) {
            service_control_1.Service.encode(v, writer.uint32(10).fork()).ldelim();
        }
        if (message.nextPageToken !== '') {
            writer.uint32(18).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({}, baseListServicesResponse);
        message.services = [];
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.services.push(service_control_1.Service.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.nextPageToken = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        var _a;
        const message = Object.assign({}, baseListServicesResponse);
        message.services = ((_a = object.services) !== null && _a !== void 0 ? _a : []).map((e) => service_control_1.Service.fromJSON(e));
        message.nextPageToken =
            object.nextPageToken !== undefined && object.nextPageToken !== null
                ? String(object.nextPageToken)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        if (message.services) {
            obj.services = message.services.map((e) => (e ? service_control_1.Service.toJSON(e) : undefined));
        }
        else {
            obj.services = [];
        }
        message.nextPageToken !== undefined && (obj.nextPageToken = message.nextPageToken);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseListServicesResponse);
        message.services = ((_a = object.services) === null || _a === void 0 ? void 0 : _a.map((e) => service_control_1.Service.fromPartial(e))) || [];
        message.nextPageToken = (_b = object.nextPageToken) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
const baseEnableServiceRequest = { serviceId: '' };
exports.EnableServiceRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseEnableServiceRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseEnableServiceRequest);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseEnableServiceRequest);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
const baseEnableServiceMetadata = { serviceId: '' };
exports.EnableServiceMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseEnableServiceMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseEnableServiceMetadata);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseEnableServiceMetadata);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
const baseDisableServiceRequest = { serviceId: '' };
exports.DisableServiceRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseDisableServiceRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDisableServiceRequest);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDisableServiceRequest);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
const baseDisableServiceMetadata = { serviceId: '' };
exports.DisableServiceMetadata = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseDisableServiceMetadata);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseDisableServiceMetadata);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseDisableServiceMetadata);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
const baseResolveServiceAgentRequest = { serviceId: '', microserviceId: '' };
exports.ResolveServiceAgentRequest = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.serviceId !== '') {
            writer.uint32(10).string(message.serviceId);
        }
        if (message.microserviceId !== '') {
            writer.uint32(18).string(message.microserviceId);
        }
        if (message.resource !== undefined) {
            resource_1.Resource.encode(message.resource, 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({}, baseResolveServiceAgentRequest);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.serviceId = reader.string();
                    break;
                case 2:
                    message.microserviceId = reader.string();
                    break;
                case 3:
                    message.resource = resource_1.Resource.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseResolveServiceAgentRequest);
        message.serviceId =
            object.serviceId !== undefined && object.serviceId !== null
                ? String(object.serviceId)
                : '';
        message.microserviceId =
            object.microserviceId !== undefined && object.microserviceId !== null
                ? String(object.microserviceId)
                : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromJSON(object.resource)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.serviceId !== undefined && (obj.serviceId = message.serviceId);
        message.microserviceId !== undefined && (obj.microserviceId = message.microserviceId);
        message.resource !== undefined &&
            (obj.resource = message.resource ? resource_1.Resource.toJSON(message.resource) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseResolveServiceAgentRequest);
        message.serviceId = (_a = object.serviceId) !== null && _a !== void 0 ? _a : '';
        message.microserviceId = (_b = object.microserviceId) !== null && _b !== void 0 ? _b : '';
        message.resource =
            object.resource !== undefined && object.resource !== null
                ? resource_1.Resource.fromPartial(object.resource)
                : undefined;
        return message;
    },
};
/** A set of methods for managing Service resources. */
exports.ServiceControlServiceService = {
    /**
     * Returns the Service information in the specified resource container.
     *
     * To get the list of available Services, make a [List] request.
     */
    get: {
        path: '/yandex.cloud.iam.v1.ServiceControlService/Get',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.GetServiceRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.GetServiceRequest.decode(value),
        responseSerialize: (value) => Buffer.from(service_control_1.Service.encode(value).finish()),
        responseDeserialize: (value) => service_control_1.Service.decode(value),
    },
    /** Retrieves the list of Service in the specified resource container. */
    list: {
        path: '/yandex.cloud.iam.v1.ServiceControlService/List',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ListServicesRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ListServicesRequest.decode(value),
        responseSerialize: (value) => Buffer.from(exports.ListServicesResponse.encode(value).finish()),
        responseDeserialize: (value) => exports.ListServicesResponse.decode(value),
    },
    /** Enable a service in the specified resource container. */
    enable: {
        path: '/yandex.cloud.iam.v1.ServiceControlService/Enable',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.EnableServiceRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.EnableServiceRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Disable a service in the specified resource container. */
    disable: {
        path: '/yandex.cloud.iam.v1.ServiceControlService/Disable',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.DisableServiceRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.DisableServiceRequest.decode(value),
        responseSerialize: (value) => Buffer.from(operation_1.Operation.encode(value).finish()),
        responseDeserialize: (value) => operation_1.Operation.decode(value),
    },
    /** Resolve agent service account for the service in the specified resource container. */
    resolveAgent: {
        path: '/yandex.cloud.iam.v1.ServiceControlService/ResolveAgent',
        requestStream: false,
        responseStream: false,
        requestSerialize: (value) => Buffer.from(exports.ResolveServiceAgentRequest.encode(value).finish()),
        requestDeserialize: (value) => exports.ResolveServiceAgentRequest.decode(value),
        responseSerialize: (value) => Buffer.from(service_control_1.ServiceAgent.encode(value).finish()),
        responseDeserialize: (value) => service_control_1.ServiceAgent.decode(value),
    },
};
exports.ServiceControlServiceClient = (0, grpc_js_1.makeGenericClientConstructor)(exports.ServiceControlServiceService, 'yandex.cloud.iam.v1.ServiceControlService');
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();
}
