"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/meta.proto
Object.defineProperty(exports, "__esModule", { value: true });
exports.protoMetadata = exports.Meta = exports.protobufPackage = void 0;
/* eslint-disable */
const wire_1 = require("@bufbuild/protobuf/wire");
const timestamp_1 = require("../../google/protobuf/timestamp");
const attribute_1 = require("./attribute");
exports.protobufPackage = "io.restorecommerce.meta";
function createBaseMeta() {
    return {};
}
exports.Meta = {
    encode(message, writer = new wire_1.BinaryWriter()) {
        if (message.created !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.created), writer.uint32(10).fork()).join();
        }
        if (message.modified !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.modified), writer.uint32(18).fork()).join();
        }
        if (message.modifiedBy !== undefined) {
            writer.uint32(26).string(message.modifiedBy);
        }
        if (message.owners !== undefined && message.owners.length !== 0) {
            for (const v of message.owners) {
                attribute_1.Attribute.encode(v, writer.uint32(34).fork()).join();
            }
        }
        if (message.acls !== undefined && message.acls.length !== 0) {
            for (const v of message.acls) {
                attribute_1.Attribute.encode(v, writer.uint32(42).fork()).join();
            }
        }
        if (message.createdBy !== undefined) {
            writer.uint32(50).string(message.createdBy);
        }
        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 = createBaseMeta();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.created = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.modified = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    continue;
                }
                case 3: {
                    if (tag !== 26) {
                        break;
                    }
                    message.modifiedBy = reader.string();
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    if (message.owners === undefined) {
                        message.owners = [];
                    }
                    const el = attribute_1.Attribute.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.owners.push(el);
                    }
                    continue;
                }
                case 5: {
                    if (tag !== 42) {
                        break;
                    }
                    if (message.acls === undefined) {
                        message.acls = [];
                    }
                    const el = attribute_1.Attribute.decode(reader, reader.uint32());
                    if (el !== undefined) {
                        message.acls.push(el);
                    }
                    continue;
                }
                case 6: {
                    if (tag !== 50) {
                        break;
                    }
                    message.createdBy = reader.string();
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            created: isSet(object.created) ? fromJsonTimestamp(object.created) : undefined,
            modified: isSet(object.modified) ? fromJsonTimestamp(object.modified) : undefined,
            modifiedBy: isSet(object.modifiedBy)
                ? globalThis.String(object.modifiedBy)
                : isSet(object.modified_by)
                    ? globalThis.String(object.modified_by)
                    : undefined,
            owners: globalThis.Array.isArray(object?.owners)
                ? object.owners.map((e) => attribute_1.Attribute.fromJSON(e))
                : undefined,
            acls: globalThis.Array.isArray(object?.acls) ? object.acls.map((e) => attribute_1.Attribute.fromJSON(e)) : undefined,
            createdBy: isSet(object.createdBy)
                ? globalThis.String(object.createdBy)
                : isSet(object.created_by)
                    ? globalThis.String(object.created_by)
                    : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.created !== undefined) {
            obj.created = message.created.toISOString();
        }
        if (message.modified !== undefined) {
            obj.modified = message.modified.toISOString();
        }
        if (message.modifiedBy !== undefined) {
            obj.modifiedBy = message.modifiedBy;
        }
        if (message.owners?.length) {
            obj.owners = message.owners.map((e) => attribute_1.Attribute.toJSON(e));
        }
        if (message.acls?.length) {
            obj.acls = message.acls.map((e) => attribute_1.Attribute.toJSON(e));
        }
        if (message.createdBy !== undefined) {
            obj.createdBy = message.createdBy;
        }
        return obj;
    },
    create(base) {
        return exports.Meta.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseMeta();
        message.created = object.created ?? undefined;
        message.modified = object.modified ?? undefined;
        message.modifiedBy = object.modifiedBy ?? undefined;
        message.owners = object.owners?.map((e) => attribute_1.Attribute.fromPartial(e)) || undefined;
        message.acls = object.acls?.map((e) => attribute_1.Attribute.fromPartial(e)) || undefined;
        message.createdBy = object.createdBy ?? undefined;
        return message;
    },
};
exports.protoMetadata = {
    fileDescriptor: {
        "name": "io/restorecommerce/meta.proto",
        "package": "io.restorecommerce.meta",
        "dependency": ["io/restorecommerce/attribute.proto", "google/protobuf/timestamp.proto"],
        "publicDependency": [],
        "weakDependency": [],
        "optionDependency": [],
        "messageType": [{
                "name": "Meta",
                "field": [{
                        "name": "created",
                        "number": 1,
                        "label": 1,
                        "type": 11,
                        "typeName": ".google.protobuf.Timestamp",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "created",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "modified",
                        "number": 2,
                        "label": 1,
                        "type": 11,
                        "typeName": ".google.protobuf.Timestamp",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 1,
                        "jsonName": "modified",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "modified_by",
                        "number": 3,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 2,
                        "jsonName": "modifiedBy",
                        "options": undefined,
                        "proto3Optional": true,
                    }, {
                        "name": "owners",
                        "number": 4,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.attribute.Attribute",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "owners",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "acls",
                        "number": 5,
                        "label": 3,
                        "type": 11,
                        "typeName": ".io.restorecommerce.attribute.Attribute",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 0,
                        "jsonName": "acls",
                        "options": undefined,
                        "proto3Optional": false,
                    }, {
                        "name": "created_by",
                        "number": 6,
                        "label": 1,
                        "type": 9,
                        "typeName": "",
                        "extendee": "",
                        "defaultValue": "",
                        "oneofIndex": 3,
                        "jsonName": "createdBy",
                        "options": undefined,
                        "proto3Optional": true,
                    }],
                "extension": [],
                "nestedType": [],
                "enumType": [],
                "extensionRange": [],
                "oneofDecl": [{ "name": "_created", "options": undefined }, { "name": "_modified", "options": undefined }, {
                        "name": "_modified_by",
                        "options": undefined,
                    }, { "name": "_created_by", "options": undefined }],
                "options": undefined,
                "reservedRange": [],
                "reservedName": [],
                "visibility": 0,
            }],
        "enumType": [],
        "service": [],
        "extension": [],
        "options": undefined,
        "sourceCodeInfo": {
            "location": [{
                    "path": [4, 0, 2, 0],
                    "span": [10, 4, 51],
                    "leadingComments": "",
                    "trailingComments": " timestamp\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 0, 2, 1],
                    "span": [11, 4, 52],
                    "leadingComments": "",
                    "trailingComments": " timestamp\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 0, 2, 2],
                    "span": [12, 4, 36],
                    "leadingComments": "",
                    "trailingComments": " ID from last User who modified resource\n",
                    "leadingDetachedComments": [],
                }, {
                    "path": [4, 0, 2, 5],
                    "span": [15, 4, 35],
                    "leadingComments": "",
                    "trailingComments": " ID from User who created resource\n",
                    "leadingDetachedComments": [],
                }],
        },
        "syntax": "proto3",
        "edition": 0,
    },
    references: { ".io.restorecommerce.meta.Meta": exports.Meta },
    dependencies: [attribute_1.protoMetadata, timestamp_1.protoMetadata],
};
function toTimestamp(date) {
    const seconds = Math.trunc(date.getTime() / 1_000);
    const nanos = (date.getTime() % 1_000) * 1_000_000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = (t.seconds || 0) * 1_000;
    millis += (t.nanos || 0) / 1_000_000;
    return new globalThis.Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof globalThis.Date) {
        return o;
    }
    else if (typeof o === "string") {
        return new globalThis.Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
function isSet(value) {
    return value !== null && value !== undefined;
}
//# sourceMappingURL=meta.js.map