"use strict";
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.8
//   protoc               v4.25.9
// source: io/restorecommerce/rule.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.protoMetadata = exports.RuleServiceDefinition = exports.ContextQuery = exports.RuleResponse = exports.RuleListResponse = exports.RuleList = exports.RuleRQ = exports.Rule = exports.Target = exports.Effect = exports.protobufPackage = void 0;
exports.effectFromJSON = effectFromJSON;
exports.effectToJSON = effectToJSON;
exports.effectToNumber = effectToNumber;
/* eslint-disable */
const wire_1 = require("@bufbuild/protobuf/wire");
const attribute_1 = require("./attribute");
const auth_1 = require("./auth");
const filter_1 = require("./filter");
const meta_1 = require("./meta");
const options_1 = require("./options");
const resource_base_1 = require("./resource_base");
const status_1 = require("./status");
exports.protobufPackage = "io.restorecommerce.rule";
/** Resulting effect from a Policy or Rule. */
var Effect;
(function (Effect) {
    Effect["PERMIT"] = "PERMIT";
    Effect["DENY"] = "DENY";
    Effect["UNRECOGNIZED"] = "UNRECOGNIZED";
})(Effect || (exports.Effect = Effect = {}));
function effectFromJSON(object) {
    switch (object) {
        case 0:
        case "PERMIT":
            return Effect.PERMIT;
        case 1:
        case "DENY":
            return Effect.DENY;
        case -1:
        case "UNRECOGNIZED":
        default:
            return Effect.UNRECOGNIZED;
    }
}
function effectToJSON(object) {
    switch (object) {
        case Effect.PERMIT:
            return "PERMIT";
        case Effect.DENY:
            return "DENY";
        case Effect.UNRECOGNIZED:
        default:
            return "UNRECOGNIZED";
    }
}
function effectToNumber(object) {
    switch (object) {
        case Effect.PERMIT:
            return 0;
        case Effect.DENY:
            return 1;
        case Effect.UNRECOGNIZED:
        default:
            return -1;
    }
}
function createBaseTarget() {
    return {};
}
exports.Target = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.subjects !== undefined && message.subjects.length !== 0) {
            for (const v of message.subjects) {
                attribute_1.Attribute.encode(v, writer.uint32(10).fork()).join();
            }
        }
        if (message.resources !== undefined && message.resources.length !== 0) {
            for (const v of message.resources) {
                attribute_1.Attribute.encode(v, writer.uint32(18).fork()).join();
            }
        }
        if (message.actions !== undefined && message.actions.length !== 0) {
            for (const v of message.actions) {
                attribute_1.Attribute.encode(v, writer.uint32(26).fork()).join();
            }
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseTarget();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    if (message.subjects === undefined) {
                        message.subjects = [];
                    }
                    const el = attribute_1.Attribute.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.subjects.push(el);
                    }
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    if (message.resources === undefined) {
                        message.resources = [];
                    }
                    const el = attribute_1.Attribute.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.resources.push(el);
                    }
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    if (message.actions === undefined) {
                        message.actions = [];
                    }
                    const el = attribute_1.Attribute.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.actions.push(el);
                    }
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            subjects: globalThis.Array.isArray(object?.subjects)
                ? object.subjects.map((e) => attribute_1.Attribute.fromJSON(e))
                : undefined,
            resources: globalThis.Array.isArray(object?.resources)
                ? object.resources.map((e) => attribute_1.Attribute.fromJSON(e))
                : undefined,
            actions: globalThis.Array.isArray(object?.actions)
                ? object.actions.map((e) => attribute_1.Attribute.fromJSON(e))
                : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.subjects?.length) {
            obj.subjects = message.subjects.map((e) => attribute_1.Attribute.toJSON(e));
        }
        if (message.resources?.length) {
            obj.resources = message.resources.map((e) => attribute_1.Attribute.toJSON(e));
        }
        if (message.actions?.length) {
            obj.actions = message.actions.map((e) => attribute_1.Attribute.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return exports.Target.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseTarget();
        message.subjects = object.subjects?.map((e) => attribute_1.Attribute.fromPartial(e)) || undefined;
        message.resources = object.resources?.map((e) => attribute_1.Attribute.fromPartial(e)) || undefined;
        message.actions = object.actions?.map((e) => attribute_1.Attribute.fromPartial(e)) || undefined;
        return message;
    },
};
function createBaseRule() {
    return {};
}
exports.Rule = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.id !== undefined) {
            writer.uint32(10).string(message.id);
        }
        if (message.meta !== undefined) {
            meta_1.Meta.encode(message.meta, writer.uint32(18).fork()).join();
        }
        if (message.name !== undefined) {
            writer.uint32(26).string(message.name);
        }
        if (message.description !== undefined) {
            writer.uint32(34).string(message.description);
        }
        if (message.target !== undefined) {
            exports.Target.encode(message.target, writer.uint32(42).fork()).join();
        }
        if (message.contextQuery !== undefined) {
            exports.ContextQuery.encode(message.contextQuery, writer.uint32(50).fork()).join();
        }
        if (message.condition !== undefined) {
            writer.uint32(58).string(message.condition);
        }
        if (message.effect !== undefined) {
            writer.uint32(64).int32(effectToNumber(message.effect));
        }
        if (message.evaluationCacheable !== undefined) {
            writer.uint32(72).bool(message.evaluationCacheable);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRule();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.meta = meta_1.Meta.decode(reader, reader.uint32());
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.name = reader.string();
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    message.description = reader.string();
                    continue;
                }
                case 5: {
                    if (tag !== 42) {
                        break;
                    }
                    message.target = exports.Target.decode(reader, reader.uint32());
                    continue;
                }
                case 6: {
                    if (tag !== 50) {
                        break;
                    }
                    message.contextQuery = exports.ContextQuery.decode(reader, reader.uint32());
                    continue;
                }
                case 7: {
                    if (tag !== 58) {
                        break;
                    }
                    message.condition = reader.string();
                    continue;
                }
                case 8: {
                    if (tag !== 64) {
                        break;
                    }
                    message.effect = effectFromJSON(reader.int32());
                    continue;
                }
                case 9: {
                    if (tag !== 72) {
                        break;
                    }
                    message.evaluationCacheable = reader.bool();
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
            meta: isSet(object.meta) ? meta_1.Meta.fromJSON(object.meta) : undefined,
            name: isSet(object.name) ? globalThis.String(object.name) : undefined,
            description: isSet(object.description) ? globalThis.String(object.description) : undefined,
            target: isSet(object.target) ? exports.Target.fromJSON(object.target) : undefined,
            contextQuery: isSet(object.contextQuery)
                ? exports.ContextQuery.fromJSON(object.contextQuery)
                : isSet(object.context_query)
                    ? exports.ContextQuery.fromJSON(object.context_query)
                    : undefined,
            condition: isSet(object.condition) ? globalThis.String(object.condition) : undefined,
            effect: isSet(object.effect) ? effectFromJSON(object.effect) : undefined,
            evaluationCacheable: isSet(object.evaluationCacheable)
                ? globalThis.Boolean(object.evaluationCacheable)
                : isSet(object.evaluation_cacheable)
                    ? globalThis.Boolean(object.evaluation_cacheable)
                    : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        if (message.meta !== undefined) {
            obj.meta = meta_1.Meta.toJSON(message.meta);
        }
        if (message.name !== undefined) {
            obj.name = message.name;
        }
        if (message.description !== undefined) {
            obj.description = message.description;
        }
        if (message.target !== undefined) {
            obj.target = exports.Target.toJSON(message.target);
        }
        if (message.contextQuery !== undefined) {
            obj.contextQuery = exports.ContextQuery.toJSON(message.contextQuery);
        }
        if (message.condition !== undefined) {
            obj.condition = message.condition;
        }
        if (message.effect !== undefined) {
            obj.effect = effectToJSON(message.effect);
        }
        if (message.evaluationCacheable !== undefined) {
            obj.evaluationCacheable = message.evaluationCacheable;
        }
        return obj;
    },
    create(base) {
        return exports.Rule.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseRule();
        message.id = object.id ?? undefined;
        message.meta = (object.meta !== undefined && object.meta !== null) ? meta_1.Meta.fromPartial(object.meta) : undefined;
        message.name = object.name ?? undefined;
        message.description = object.description ?? undefined;
        message.target = (object.target !== undefined && object.target !== null)
            ? exports.Target.fromPartial(object.target)
            : undefined;
        message.contextQuery = (object.contextQuery !== undefined && object.contextQuery !== null)
            ? exports.ContextQuery.fromPartial(object.contextQuery)
            : undefined;
        message.condition = object.condition ?? undefined;
        message.effect = object.effect ?? undefined;
        message.evaluationCacheable = object.evaluationCacheable ?? undefined;
        return message;
    },
};
function createBaseRuleRQ() {
    return {};
}
exports.RuleRQ = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.id !== undefined) {
            writer.uint32(10).string(message.id);
        }
        if (message.target !== undefined) {
            exports.Target.encode(message.target, writer.uint32(18).fork()).join();
        }
        if (message.effect !== undefined) {
            writer.uint32(24).int32(effectToNumber(message.effect));
        }
        if (message.condition !== undefined) {
            writer.uint32(34).string(message.condition);
        }
        if (message.contextQuery !== undefined) {
            exports.ContextQuery.encode(message.contextQuery, writer.uint32(42).fork()).join();
        }
        if (message.evaluationCacheable !== undefined) {
            writer.uint32(48).bool(message.evaluationCacheable);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRuleRQ();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.target = exports.Target.decode(reader, reader.uint32());
                    continue;
                }
                case 3: {
                    if (tag !== 24) {
                        break;
                    }
                    message.effect = effectFromJSON(reader.int32());
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    message.condition = reader.string();
                    continue;
                }
                case 5: {
                    if (tag !== 42) {
                        break;
                    }
                    message.contextQuery = exports.ContextQuery.decode(reader, reader.uint32());
                    continue;
                }
                case 6: {
                    if (tag !== 48) {
                        break;
                    }
                    message.evaluationCacheable = reader.bool();
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
            target: isSet(object.target) ? exports.Target.fromJSON(object.target) : undefined,
            effect: isSet(object.effect) ? effectFromJSON(object.effect) : undefined,
            condition: isSet(object.condition) ? globalThis.String(object.condition) : undefined,
            contextQuery: isSet(object.contextQuery)
                ? exports.ContextQuery.fromJSON(object.contextQuery)
                : isSet(object.context_query)
                    ? exports.ContextQuery.fromJSON(object.context_query)
                    : undefined,
            evaluationCacheable: isSet(object.evaluationCacheable)
                ? globalThis.Boolean(object.evaluationCacheable)
                : isSet(object.evaluation_cacheable)
                    ? globalThis.Boolean(object.evaluation_cacheable)
                    : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        if (message.target !== undefined) {
            obj.target = exports.Target.toJSON(message.target);
        }
        if (message.effect !== undefined) {
            obj.effect = effectToJSON(message.effect);
        }
        if (message.condition !== undefined) {
            obj.condition = message.condition;
        }
        if (message.contextQuery !== undefined) {
            obj.contextQuery = exports.ContextQuery.toJSON(message.contextQuery);
        }
        if (message.evaluationCacheable !== undefined) {
            obj.evaluationCacheable = message.evaluationCacheable;
        }
        return obj;
    },
    create(base) {
        return exports.RuleRQ.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseRuleRQ();
        message.id = object.id ?? undefined;
        message.target = (object.target !== undefined && object.target !== null)
            ? exports.Target.fromPartial(object.target)
            : undefined;
        message.effect = object.effect ?? undefined;
        message.condition = object.condition ?? undefined;
        message.contextQuery = (object.contextQuery !== undefined && object.contextQuery !== null)
            ? exports.ContextQuery.fromPartial(object.contextQuery)
            : undefined;
        message.evaluationCacheable = object.evaluationCacheable ?? undefined;
        return message;
    },
};
function createBaseRuleList() {
    return {};
}
exports.RuleList = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.items !== undefined && message.items.length !== 0) {
            for (const v of message.items) {
                exports.Rule.encode(v, writer.uint32(10).fork()).join();
            }
        }
        if (message.totalCount !== undefined) {
            writer.uint32(16).uint32(message.totalCount);
        }
        if (message.subject !== undefined) {
            auth_1.Subject.encode(message.subject, writer.uint32(26).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRuleList();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    if (message.items === undefined) {
                        message.items = [];
                    }
                    const el = exports.Rule.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.items.push(el);
                    }
                    continue;
                }
                case 2: {
                    if (tag !== 16) {
                        break;
                    }
                    message.totalCount = reader.uint32();
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.subject = auth_1.Subject.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            items: globalThis.Array.isArray(object?.items) ? object.items.map((e) => exports.Rule.fromJSON(e)) : undefined,
            totalCount: isSet(object.totalCount)
                ? globalThis.Number(object.totalCount)
                : isSet(object.total_count)
                    ? globalThis.Number(object.total_count)
                    : undefined,
            subject: isSet(object.subject) ? auth_1.Subject.fromJSON(object.subject) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.items?.length) {
            obj.items = message.items.map((e) => exports.Rule.toJSON(e));
        }
        if (message.totalCount !== undefined) {
            obj.totalCount = Math.round(message.totalCount);
        }
        if (message.subject !== undefined) {
            obj.subject = auth_1.Subject.toJSON(message.subject);
        }
        return obj;
    },
    create(base) {
        return exports.RuleList.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseRuleList();
        message.items = object.items?.map((e) => exports.Rule.fromPartial(e)) || undefined;
        message.totalCount = object.totalCount ?? undefined;
        message.subject = (object.subject !== undefined && object.subject !== null)
            ? auth_1.Subject.fromPartial(object.subject)
            : undefined;
        return message;
    },
};
function createBaseRuleListResponse() {
    return {};
}
exports.RuleListResponse = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.items !== undefined && message.items.length !== 0) {
            for (const v of message.items) {
                exports.RuleResponse.encode(v, writer.uint32(10).fork()).join();
            }
        }
        if (message.totalCount !== undefined) {
            writer.uint32(16).uint32(message.totalCount);
        }
        if (message.operationStatus !== undefined) {
            status_1.OperationStatus.encode(message.operationStatus, writer.uint32(26).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRuleListResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    if (message.items === undefined) {
                        message.items = [];
                    }
                    const el = exports.RuleResponse.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.items.push(el);
                    }
                    continue;
                }
                case 2: {
                    if (tag !== 16) {
                        break;
                    }
                    message.totalCount = reader.uint32();
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.operationStatus = status_1.OperationStatus.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            items: globalThis.Array.isArray(object?.items)
                ? object.items.map((e) => exports.RuleResponse.fromJSON(e))
                : undefined,
            totalCount: isSet(object.totalCount)
                ? globalThis.Number(object.totalCount)
                : isSet(object.total_count)
                    ? globalThis.Number(object.total_count)
                    : undefined,
            operationStatus: isSet(object.operationStatus)
                ? status_1.OperationStatus.fromJSON(object.operationStatus)
                : isSet(object.operation_status)
                    ? status_1.OperationStatus.fromJSON(object.operation_status)
                    : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.items?.length) {
            obj.items = message.items.map((e) => exports.RuleResponse.toJSON(e));
        }
        if (message.totalCount !== undefined) {
            obj.totalCount = Math.round(message.totalCount);
        }
        if (message.operationStatus !== undefined) {
            obj.operationStatus = status_1.OperationStatus.toJSON(message.operationStatus);
        }
        return obj;
    },
    create(base) {
        return exports.RuleListResponse.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseRuleListResponse();
        message.items = object.items?.map((e) => exports.RuleResponse.fromPartial(e)) || undefined;
        message.totalCount = object.totalCount ?? undefined;
        message.operationStatus = (object.operationStatus !== undefined && object.operationStatus !== null)
            ? status_1.OperationStatus.fromPartial(object.operationStatus)
            : undefined;
        return message;
    },
};
function createBaseRuleResponse() {
    return {};
}
exports.RuleResponse = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.payload !== undefined) {
            exports.Rule.encode(message.payload, writer.uint32(10).fork()).join();
        }
        if (message.status !== undefined) {
            status_1.Status.encode(message.status, writer.uint32(18).fork()).join();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseRuleResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.payload = exports.Rule.decode(reader, reader.uint32());
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.status = status_1.Status.decode(reader, reader.uint32());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            payload: isSet(object.payload) ? exports.Rule.fromJSON(object.payload) : undefined,
            status: isSet(object.status) ? status_1.Status.fromJSON(object.status) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.payload !== undefined) {
            obj.payload = exports.Rule.toJSON(message.payload);
        }
        if (message.status !== undefined) {
            obj.status = status_1.Status.toJSON(message.status);
        }
        return obj;
    },
    create(base) {
        return exports.RuleResponse.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseRuleResponse();
        message.payload = (object.payload !== undefined && object.payload !== null)
            ? exports.Rule.fromPartial(object.payload)
            : undefined;
        message.status = (object.status !== undefined && object.status !== null)
            ? status_1.Status.fromPartial(object.status)
            : undefined;
        return message;
    },
};
function createBaseContextQuery() {
    return {};
}
exports.ContextQuery = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.filters !== undefined && message.filters.length !== 0) {
            for (const v of message.filters) {
                filter_1.FilterOp.encode(v, writer.uint32(10).fork()).join();
            }
        }
        if (message.query !== undefined) {
            writer.uint32(18).string(message.query);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseContextQuery();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    if (message.filters === undefined) {
                        message.filters = [];
                    }
                    const el = filter_1.FilterOp.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.filters.push(el);
                    }
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.query = reader.string();
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            filters: globalThis.Array.isArray(object?.filters)
                ? object.filters.map((e) => filter_1.FilterOp.fromJSON(e))
                : undefined,
            query: isSet(object.query) ? globalThis.String(object.query) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.filters?.length) {
            obj.filters = message.filters.map((e) => filter_1.FilterOp.toJSON(e));
        }
        if (message.query !== undefined) {
            obj.query = message.query;
        }
        return obj;
    },
    create(base) {
        return exports.ContextQuery.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseContextQuery();
        message.filters = object.filters?.map((e) => filter_1.FilterOp.fromPartial(e)) || undefined;
        message.query = object.query ?? undefined;
        return message;
    },
};
exports.RuleServiceDefinition = {
    name: "RuleService",
    fullName: "io.restorecommerce.rule.RuleService",
    methods: {
        read: {
            name: "Read",
            requestType: resource_base_1.ReadRequest,
            requestStream: false,
            responseType: exports.RuleListResponse,
            responseStream: false,
            options: { _unknownFields: { 248008: [Buffer.from([1])] } },
        },
        create: {
            name: "Create",
            requestType: exports.RuleList,
            requestStream: false,
            responseType: exports.RuleListResponse,
            responseStream: false,
            options: {},
        },
        delete: {
            name: "Delete",
            requestType: resource_base_1.DeleteRequest,
            requestStream: false,
            responseType: resource_base_1.DeleteResponse,
            responseStream: false,
            options: {},
        },
        update: {
            name: "Update",
            requestType: exports.RuleList,
            requestStream: false,
            responseType: exports.RuleListResponse,
            responseStream: false,
            options: {},
        },
        upsert: {
            name: "Upsert",
            requestType: exports.RuleList,
            requestStream: false,
            responseType: exports.RuleListResponse,
            responseStream: false,
            options: {},
        },
    },
};
exports.protoMetadata = {
    fileDescriptor: {
        "name": "io/restorecommerce/rule.proto",
        "package": "io.restorecommerce.rule",
        "dependency": [
            "io/restorecommerce/resource_base.proto",
            "io/restorecommerce/meta.proto",
            "io/restorecommerce/auth.proto",
            "io/restorecommerce/attribute.proto",
            "io/restorecommerce/status.proto",
            "io/restorecommerce/filter.proto",
            "io/restorecommerce/options.proto",
        ],
        "publicDependency": [],
        "weakDependency": [],
        "optionDependency": [],
        "messageType": [{
                "name": "Target",
                "field": [{
                        "name": "subjects",
                        "number": 1,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.attribute.Attribute",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "subjects",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "resources",
                        "number": 2,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.attribute.Attribute",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "resources",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "actions",
                        "number": 3,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.attribute.Attribute",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "actions",
                        "options": undefined,
                        "proto3Optional": false,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "Rule",
                "field": [{
                        "name": "id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "id",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "meta",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.meta.Meta",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "meta",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "name",
                        "number": 3,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "name",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "description",
                        "number": 4,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 3,
                        "jsonName": "description",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "target",
                        "number": 5,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.Target",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 4,
                        "jsonName": "target",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "context_query",
                        "number": 6,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.ContextQuery",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 5,
                        "jsonName": "contextQuery",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "condition",
                        "number": 7,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 6,
                        "jsonName": "condition",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "effect",
                        "number": 8,
                        "label": 1,
                        "type": 14,
                        "typeName": ".io.restorecommerce.rule.Effect",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 7,
                        "jsonName": "effect",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "evaluation_cacheable",
                        "number": 9,
                        "label": 1,
                        "type": 8,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 8,
                        "jsonName": "evaluationCacheable",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [
                    { "name": "_id", "options": undefined },
                    { "name": "_meta", "options": undefined },
                    { "name": "_name", "options": undefined },
                    { "name": "_description", "options": undefined },
                    { "name": "_target", "options": undefined },
                    { "name": "_context_query", "options": undefined },
                    { "name": "_condition", "options": undefined },
                    { "name": "_effect", "options": undefined },
                    { "name": "_evaluation_cacheable", "options": undefined },
                ],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "RuleRQ",
                "field": [{
                        "name": "id",
                        "number": 1,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "id",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "target",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.Target",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "target",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "effect",
                        "number": 3,
                        "label": 1,
                        "type": 14,
                        "typeName": ".io.restorecommerce.rule.Effect",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "effect",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "condition",
                        "number": 4,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 3,
                        "jsonName": "condition",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "context_query",
                        "number": 5,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.ContextQuery",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 4,
                        "jsonName": "contextQuery",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "evaluation_cacheable",
                        "number": 6,
                        "label": 1,
                        "type": 8,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 5,
                        "jsonName": "evaluationCacheable",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [
                    { "name": "_id", "options": undefined },
                    { "name": "_target", "options": undefined },
                    { "name": "_effect", "options": undefined },
                    { "name": "_condition", "options": undefined },
                    { "name": "_context_query", "options": undefined },
                    { "name": "_evaluation_cacheable", "options": undefined },
                ],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "RuleList",
                "field": [{
                        "name": "items",
                        "number": 1,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.Rule",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "items",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "total_count",
                        "number": 2,
                        "label": 1,
                        "type": 13,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "totalCount",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "subject",
                        "number": 3,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.auth.Subject",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "subject",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_total_count", "options": undefined }, { "name": "_subject", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "RuleListResponse",
                "field": [{
                        "name": "items",
                        "number": 1,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.RuleResponse",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "items",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "total_count",
                        "number": 2,
                        "label": 1,
                        "type": 13,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "totalCount",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "operation_status",
                        "number": 3,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.status.OperationStatus",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "operationStatus",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_total_count", "options": undefined }, {
                        "name": "_operation_status",
                        "options": undefined,
                    }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "RuleResponse",
                "field": [{
                        "name": "payload",
                        "number": 1,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.rule.Rule",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "payload",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "status",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".io.restorecommerce.status.Status",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "status",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_payload", "options": undefined }, { "name": "_status", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }, {
                "name": "ContextQuery",
                "field": [{
                        "name": "filters",
                        "number": 1,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.filter.FilterOp",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "filters",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "query",
                        "number": 2,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "query",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_query", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }],
        "enumType": [{
                "name": "Effect",
                "value": [{ "name": "PERMIT", "number": 0, "options": undefined }, {
                        "name": "DENY",
                        "number": 1,
                        "options": undefined,
                    }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }],
        "service": [{
                "name": "RuleService",
                "method": [{
                        "name": "Read",
                        "inputType": ".io.restorecommerce.resourcebase.ReadRequest",
                        "outputType": ".io.restorecommerce.rule.RuleListResponse",
                        "options": { "deprecated": false, "idempotencyLevel": 0, "features": undefined, "uninterpretedOption": [] },
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "Create",
                        "inputType": ".io.restorecommerce.rule.RuleList",
                        "outputType": ".io.restorecommerce.rule.RuleListResponse",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "Delete",
                        "inputType": ".io.restorecommerce.resourcebase.DeleteRequest",
                        "outputType": ".io.restorecommerce.resourcebase.DeleteResponse",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "Update",
                        "inputType": ".io.restorecommerce.rule.RuleList",
                        "outputType": ".io.restorecommerce.rule.RuleListResponse",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }, {
                        "name": "Upsert",
                        "inputType": ".io.restorecommerce.rule.RuleList",
                        "outputType": ".io.restorecommerce.rule.RuleListResponse",
                        "options": undefined,
                        "clientStreaming": false,
                        "serverStreaming": false,
                    }],
                "options": undefined,
            }],
        "extension": [],
        "options": undefined,
        "sourceCodeInfo": {
            "location": [{
                    "path": [4, 0],
                    "span": [15, 0, 19, 1],
                    "leadingComments": "*\n Target specified by a Rule or a Request.\n",
                    "trailingComments": "",
                    "leadingDetachedComments": [],
                }, {
                    "path": [5, 0],
                    "span": [24, 0, 27, 1],
                    "leadingComments": "*\n Resulting effect from a Policy or Rule.\n",
                    "trailingComments": "",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 1, 2, 6],
                    "span": [36, 2, 32],
                    "leadingComments": "",
                    "trailingComments": " JS code\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 2],
                    "span": [41, 0, 48, 1],
                    "leadingComments": "",
                    "trailingComments": " used for `whatIsAllowed` / reverse queries\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 6],
                    "span": [70, 0, 73, 1],
                    "leadingComments": " Query to pull resources from an external service\n  and append them to the request's context.\n The retrieved data can then be passed onto the request's context\n",
                    "trailingComments": "",
                    "leadingDetachedComments": [],
                }],
        },
        "syntax": "proto3",
        "edition": 0,
    },
    references: {
        ".io.restorecommerce.rule.Effect": Effect,
        ".io.restorecommerce.rule.Target": exports.Target,
        ".io.restorecommerce.rule.Rule": exports.Rule,
        ".io.restorecommerce.rule.RuleRQ": exports.RuleRQ,
        ".io.restorecommerce.rule.RuleList": exports.RuleList,
        ".io.restorecommerce.rule.RuleListResponse": exports.RuleListResponse,
        ".io.restorecommerce.rule.RuleResponse": exports.RuleResponse,
        ".io.restorecommerce.rule.ContextQuery": exports.ContextQuery,
    },
    dependencies: [
        resource_base_1.protoMetadata,
        meta_1.protoMetadata,
        auth_1.protoMetadata,
        attribute_1.protoMetadata,
        status_1.protoMetadata,
        filter_1.protoMetadata,
        options_1.protoMetadata,
    ],
    options: { services: { "RuleService": { methods: { "Read": { "is_query": true } } } } },
};
function isSet(value) {
    return value !== null && value !== undefined;
}
//# sourceMappingURL=rule.js.map