"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HistoryEntryError = exports.HistoryEntryOutput = exports.HistoryEntryInput = exports.HistoryEntry_FailedAttempt = exports.HistoryEntry = exports.historyEntry_StatusToJSON = exports.historyEntry_StatusFromJSON = exports.HistoryEntry_Status = exports.protobufPackage = void 0;
/* eslint-disable */
const long_1 = __importDefault(require("long"));
const minimal_1 = __importDefault(require("protobufjs/minimal"));
const duration_1 = require("../../../../../google/protobuf/duration");
const timestamp_1 = require("../../../../../google/protobuf/timestamp");
exports.protobufPackage = 'yandex.cloud.serverless.workflows.v1';
var HistoryEntry_Status;
(function (HistoryEntry_Status) {
    HistoryEntry_Status[HistoryEntry_Status["STATUS_UNSPECIFIED"] = 0] = "STATUS_UNSPECIFIED";
    /** SCHEDULED - Step execution is being scheduled. */
    HistoryEntry_Status[HistoryEntry_Status["SCHEDULED"] = 1] = "SCHEDULED";
    /** STARTED - Step execution is started. */
    HistoryEntry_Status[HistoryEntry_Status["STARTED"] = 2] = "STARTED";
    /** COMPLETED - Step execution is completed. */
    HistoryEntry_Status[HistoryEntry_Status["COMPLETED"] = 3] = "COMPLETED";
    /** FAILED - Step execution is failed. */
    HistoryEntry_Status[HistoryEntry_Status["FAILED"] = 4] = "FAILED";
    /** CANCEL_REQUESTED - Step execution is requested to be cancelled. */
    HistoryEntry_Status[HistoryEntry_Status["CANCEL_REQUESTED"] = 5] = "CANCEL_REQUESTED";
    /** CANCELLED - Step execution is canceled. */
    HistoryEntry_Status[HistoryEntry_Status["CANCELLED"] = 6] = "CANCELLED";
    HistoryEntry_Status[HistoryEntry_Status["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(HistoryEntry_Status = exports.HistoryEntry_Status || (exports.HistoryEntry_Status = {}));
function historyEntry_StatusFromJSON(object) {
    switch (object) {
        case 0:
        case 'STATUS_UNSPECIFIED':
            return HistoryEntry_Status.STATUS_UNSPECIFIED;
        case 1:
        case 'SCHEDULED':
            return HistoryEntry_Status.SCHEDULED;
        case 2:
        case 'STARTED':
            return HistoryEntry_Status.STARTED;
        case 3:
        case 'COMPLETED':
            return HistoryEntry_Status.COMPLETED;
        case 4:
        case 'FAILED':
            return HistoryEntry_Status.FAILED;
        case 5:
        case 'CANCEL_REQUESTED':
            return HistoryEntry_Status.CANCEL_REQUESTED;
        case 6:
        case 'CANCELLED':
            return HistoryEntry_Status.CANCELLED;
        case -1:
        case 'UNRECOGNIZED':
        default:
            return HistoryEntry_Status.UNRECOGNIZED;
    }
}
exports.historyEntry_StatusFromJSON = historyEntry_StatusFromJSON;
function historyEntry_StatusToJSON(object) {
    switch (object) {
        case HistoryEntry_Status.STATUS_UNSPECIFIED:
            return 'STATUS_UNSPECIFIED';
        case HistoryEntry_Status.SCHEDULED:
            return 'SCHEDULED';
        case HistoryEntry_Status.STARTED:
            return 'STARTED';
        case HistoryEntry_Status.COMPLETED:
            return 'COMPLETED';
        case HistoryEntry_Status.FAILED:
            return 'FAILED';
        case HistoryEntry_Status.CANCEL_REQUESTED:
            return 'CANCEL_REQUESTED';
        case HistoryEntry_Status.CANCELLED:
            return 'CANCELLED';
        default:
            return 'UNKNOWN';
    }
}
exports.historyEntry_StatusToJSON = historyEntry_StatusToJSON;
const baseHistoryEntry = {
    id: '',
    title: '',
    description: '',
    status: 0,
    type: '',
    attempts: 0,
};
exports.HistoryEntry = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.id !== '') {
            writer.uint32(10).string(message.id);
        }
        if (message.title !== '') {
            writer.uint32(18).string(message.title);
        }
        if (message.description !== '') {
            writer.uint32(26).string(message.description);
        }
        if (message.startedAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.startedAt), writer.uint32(34).fork()).ldelim();
        }
        if (message.duration !== undefined) {
            duration_1.Duration.encode(message.duration, writer.uint32(42).fork()).ldelim();
        }
        if (message.input !== undefined) {
            exports.HistoryEntryInput.encode(message.input, writer.uint32(50).fork()).ldelim();
        }
        if (message.output !== undefined) {
            exports.HistoryEntryOutput.encode(message.output, writer.uint32(58).fork()).ldelim();
        }
        if (message.error !== undefined) {
            exports.HistoryEntryError.encode(message.error, writer.uint32(66).fork()).ldelim();
        }
        if (message.status !== 0) {
            writer.uint32(72).int32(message.status);
        }
        if (message.type !== '') {
            writer.uint32(82).string(message.type);
        }
        if (message.attempts !== 0) {
            writer.uint32(96).int64(message.attempts);
        }
        if (message.lastError !== undefined) {
            exports.HistoryEntryError.encode(message.lastError, writer.uint32(106).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({}, baseHistoryEntry);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.id = reader.string();
                    break;
                case 2:
                    message.title = reader.string();
                    break;
                case 3:
                    message.description = reader.string();
                    break;
                case 4:
                    message.startedAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 5:
                    message.duration = duration_1.Duration.decode(reader, reader.uint32());
                    break;
                case 6:
                    message.input = exports.HistoryEntryInput.decode(reader, reader.uint32());
                    break;
                case 7:
                    message.output = exports.HistoryEntryOutput.decode(reader, reader.uint32());
                    break;
                case 8:
                    message.error = exports.HistoryEntryError.decode(reader, reader.uint32());
                    break;
                case 9:
                    message.status = reader.int32();
                    break;
                case 10:
                    message.type = reader.string();
                    break;
                case 12:
                    message.attempts = longToNumber(reader.int64());
                    break;
                case 13:
                    message.lastError = exports.HistoryEntryError.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHistoryEntry);
        message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
        message.title =
            object.title !== undefined && object.title !== null ? String(object.title) : '';
        message.description =
            object.description !== undefined && object.description !== null
                ? String(object.description)
                : '';
        message.startedAt =
            object.startedAt !== undefined && object.startedAt !== null
                ? fromJsonTimestamp(object.startedAt)
                : undefined;
        message.duration =
            object.duration !== undefined && object.duration !== null
                ? duration_1.Duration.fromJSON(object.duration)
                : undefined;
        message.input =
            object.input !== undefined && object.input !== null
                ? exports.HistoryEntryInput.fromJSON(object.input)
                : undefined;
        message.output =
            object.output !== undefined && object.output !== null
                ? exports.HistoryEntryOutput.fromJSON(object.output)
                : undefined;
        message.error =
            object.error !== undefined && object.error !== null
                ? exports.HistoryEntryError.fromJSON(object.error)
                : undefined;
        message.status =
            object.status !== undefined && object.status !== null
                ? historyEntry_StatusFromJSON(object.status)
                : 0;
        message.type = object.type !== undefined && object.type !== null ? String(object.type) : '';
        message.attempts =
            object.attempts !== undefined && object.attempts !== null ? Number(object.attempts) : 0;
        message.lastError =
            object.lastError !== undefined && object.lastError !== null
                ? exports.HistoryEntryError.fromJSON(object.lastError)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.id !== undefined && (obj.id = message.id);
        message.title !== undefined && (obj.title = message.title);
        message.description !== undefined && (obj.description = message.description);
        message.startedAt !== undefined && (obj.startedAt = message.startedAt.toISOString());
        message.duration !== undefined &&
            (obj.duration = message.duration ? duration_1.Duration.toJSON(message.duration) : undefined);
        message.input !== undefined &&
            (obj.input = message.input ? exports.HistoryEntryInput.toJSON(message.input) : undefined);
        message.output !== undefined &&
            (obj.output = message.output ? exports.HistoryEntryOutput.toJSON(message.output) : undefined);
        message.error !== undefined &&
            (obj.error = message.error ? exports.HistoryEntryError.toJSON(message.error) : undefined);
        message.status !== undefined && (obj.status = historyEntry_StatusToJSON(message.status));
        message.type !== undefined && (obj.type = message.type);
        message.attempts !== undefined && (obj.attempts = Math.round(message.attempts));
        message.lastError !== undefined &&
            (obj.lastError = message.lastError
                ? exports.HistoryEntryError.toJSON(message.lastError)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a, _b, _c, _d, _e, _f, _g;
        const message = Object.assign({}, baseHistoryEntry);
        message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
        message.title = (_b = object.title) !== null && _b !== void 0 ? _b : '';
        message.description = (_c = object.description) !== null && _c !== void 0 ? _c : '';
        message.startedAt = (_d = object.startedAt) !== null && _d !== void 0 ? _d : undefined;
        message.duration =
            object.duration !== undefined && object.duration !== null
                ? duration_1.Duration.fromPartial(object.duration)
                : undefined;
        message.input =
            object.input !== undefined && object.input !== null
                ? exports.HistoryEntryInput.fromPartial(object.input)
                : undefined;
        message.output =
            object.output !== undefined && object.output !== null
                ? exports.HistoryEntryOutput.fromPartial(object.output)
                : undefined;
        message.error =
            object.error !== undefined && object.error !== null
                ? exports.HistoryEntryError.fromPartial(object.error)
                : undefined;
        message.status = (_e = object.status) !== null && _e !== void 0 ? _e : 0;
        message.type = (_f = object.type) !== null && _f !== void 0 ? _f : '';
        message.attempts = (_g = object.attempts) !== null && _g !== void 0 ? _g : 0;
        message.lastError =
            object.lastError !== undefined && object.lastError !== null
                ? exports.HistoryEntryError.fromPartial(object.lastError)
                : undefined;
        return message;
    },
};
const baseHistoryEntry_FailedAttempt = {};
exports.HistoryEntry_FailedAttempt = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.startedAt !== undefined) {
            timestamp_1.Timestamp.encode(toTimestamp(message.startedAt), writer.uint32(10).fork()).ldelim();
        }
        if (message.duration !== undefined) {
            duration_1.Duration.encode(message.duration, writer.uint32(18).fork()).ldelim();
        }
        if (message.error !== undefined) {
            exports.HistoryEntryError.encode(message.error, 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({}, baseHistoryEntry_FailedAttempt);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.startedAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
                    break;
                case 2:
                    message.duration = duration_1.Duration.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.error = exports.HistoryEntryError.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHistoryEntry_FailedAttempt);
        message.startedAt =
            object.startedAt !== undefined && object.startedAt !== null
                ? fromJsonTimestamp(object.startedAt)
                : undefined;
        message.duration =
            object.duration !== undefined && object.duration !== null
                ? duration_1.Duration.fromJSON(object.duration)
                : undefined;
        message.error =
            object.error !== undefined && object.error !== null
                ? exports.HistoryEntryError.fromJSON(object.error)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.startedAt !== undefined && (obj.startedAt = message.startedAt.toISOString());
        message.duration !== undefined &&
            (obj.duration = message.duration ? duration_1.Duration.toJSON(message.duration) : undefined);
        message.error !== undefined &&
            (obj.error = message.error ? exports.HistoryEntryError.toJSON(message.error) : undefined);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseHistoryEntry_FailedAttempt);
        message.startedAt = (_a = object.startedAt) !== null && _a !== void 0 ? _a : undefined;
        message.duration =
            object.duration !== undefined && object.duration !== null
                ? duration_1.Duration.fromPartial(object.duration)
                : undefined;
        message.error =
            object.error !== undefined && object.error !== null
                ? exports.HistoryEntryError.fromPartial(object.error)
                : undefined;
        return message;
    },
};
const baseHistoryEntryInput = {};
exports.HistoryEntryInput = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.inputJson !== undefined) {
            writer.uint32(10).string(message.inputJson);
        }
        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({}, baseHistoryEntryInput);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.inputJson = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHistoryEntryInput);
        message.inputJson =
            object.inputJson !== undefined && object.inputJson !== null
                ? String(object.inputJson)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.inputJson !== undefined && (obj.inputJson = message.inputJson);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseHistoryEntryInput);
        message.inputJson = (_a = object.inputJson) !== null && _a !== void 0 ? _a : undefined;
        return message;
    },
};
const baseHistoryEntryOutput = {};
exports.HistoryEntryOutput = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.outputJson !== undefined) {
            writer.uint32(10).string(message.outputJson);
        }
        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({}, baseHistoryEntryOutput);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.outputJson = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHistoryEntryOutput);
        message.outputJson =
            object.outputJson !== undefined && object.outputJson !== null
                ? String(object.outputJson)
                : undefined;
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.outputJson !== undefined && (obj.outputJson = message.outputJson);
        return obj;
    },
    fromPartial(object) {
        var _a;
        const message = Object.assign({}, baseHistoryEntryOutput);
        message.outputJson = (_a = object.outputJson) !== null && _a !== void 0 ? _a : undefined;
        return message;
    },
};
const baseHistoryEntryError = { message: '', errorCode: '' };
exports.HistoryEntryError = {
    encode(message, writer = minimal_1.default.Writer.create()) {
        if (message.message !== '') {
            writer.uint32(10).string(message.message);
        }
        if (message.errorCode !== '') {
            writer.uint32(18).string(message.errorCode);
        }
        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({}, baseHistoryEntryError);
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.message = reader.string();
                    break;
                case 2:
                    message.errorCode = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        const message = Object.assign({}, baseHistoryEntryError);
        message.message =
            object.message !== undefined && object.message !== null ? String(object.message) : '';
        message.errorCode =
            object.errorCode !== undefined && object.errorCode !== null
                ? String(object.errorCode)
                : '';
        return message;
    },
    toJSON(message) {
        const obj = {};
        message.message !== undefined && (obj.message = message.message);
        message.errorCode !== undefined && (obj.errorCode = message.errorCode);
        return obj;
    },
    fromPartial(object) {
        var _a, _b;
        const message = Object.assign({}, baseHistoryEntryError);
        message.message = (_a = object.message) !== null && _a !== void 0 ? _a : '';
        message.errorCode = (_b = object.errorCode) !== null && _b !== void 0 ? _b : '';
        return message;
    },
};
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 toTimestamp(date) {
    const seconds = date.getTime() / 1000;
    const nanos = (date.getTime() % 1000) * 1000000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = t.seconds * 1000;
    millis += t.nanos / 1000000;
    return new Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof Date) {
        return o;
    }
    else if (typeof o === 'string') {
        return new Date(o);
    }
    else {
        return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
    }
}
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();
}
