//@ts-nocheck
import { Timeout, Order, orderFromJSON, orderToJSON, } from './channel.js';
import { BinaryReader, BinaryWriter } from '../../../../binary.js';
import { isSet } from '../../../../helpers.js';
import {} from '../../../../json-safe.js';
function createBaseUpgrade() {
    return {
        fields: UpgradeFields.fromPartial({}),
        timeout: Timeout.fromPartial({}),
        nextSequenceSend: BigInt(0),
    };
}
export const Upgrade = {
    typeUrl: '/ibc.core.channel.v1.Upgrade',
    encode(message, writer = BinaryWriter.create()) {
        if (message.fields !== undefined) {
            UpgradeFields.encode(message.fields, writer.uint32(10).fork()).ldelim();
        }
        if (message.timeout !== undefined) {
            Timeout.encode(message.timeout, writer.uint32(18).fork()).ldelim();
        }
        if (message.nextSequenceSend !== BigInt(0)) {
            writer.uint32(24).uint64(message.nextSequenceSend);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseUpgrade();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.fields = UpgradeFields.decode(reader, reader.uint32());
                    break;
                case 2:
                    message.timeout = Timeout.decode(reader, reader.uint32());
                    break;
                case 3:
                    message.nextSequenceSend = reader.uint64();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            fields: isSet(object.fields)
                ? UpgradeFields.fromJSON(object.fields)
                : undefined,
            timeout: isSet(object.timeout)
                ? Timeout.fromJSON(object.timeout)
                : undefined,
            nextSequenceSend: isSet(object.nextSequenceSend)
                ? BigInt(object.nextSequenceSend.toString())
                : BigInt(0),
        };
    },
    toJSON(message) {
        const obj = {};
        message.fields !== undefined &&
            (obj.fields = message.fields
                ? UpgradeFields.toJSON(message.fields)
                : undefined);
        message.timeout !== undefined &&
            (obj.timeout = message.timeout
                ? Timeout.toJSON(message.timeout)
                : undefined);
        message.nextSequenceSend !== undefined &&
            (obj.nextSequenceSend = (message.nextSequenceSend || BigInt(0)).toString());
        return obj;
    },
    fromPartial(object) {
        const message = createBaseUpgrade();
        message.fields =
            object.fields !== undefined && object.fields !== null
                ? UpgradeFields.fromPartial(object.fields)
                : undefined;
        message.timeout =
            object.timeout !== undefined && object.timeout !== null
                ? Timeout.fromPartial(object.timeout)
                : undefined;
        message.nextSequenceSend =
            object.nextSequenceSend !== undefined && object.nextSequenceSend !== null
                ? BigInt(object.nextSequenceSend.toString())
                : BigInt(0);
        return message;
    },
    fromProtoMsg(message) {
        return Upgrade.decode(message.value);
    },
    toProto(message) {
        return Upgrade.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/ibc.core.channel.v1.Upgrade',
            value: Upgrade.encode(message).finish(),
        };
    },
};
function createBaseUpgradeFields() {
    return {
        ordering: 0,
        connectionHops: [],
        version: '',
    };
}
export const UpgradeFields = {
    typeUrl: '/ibc.core.channel.v1.UpgradeFields',
    encode(message, writer = BinaryWriter.create()) {
        if (message.ordering !== 0) {
            writer.uint32(8).int32(message.ordering);
        }
        for (const v of message.connectionHops) {
            writer.uint32(18).string(v);
        }
        if (message.version !== '') {
            writer.uint32(26).string(message.version);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseUpgradeFields();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.ordering = reader.int32();
                    break;
                case 2:
                    message.connectionHops.push(reader.string());
                    break;
                case 3:
                    message.version = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            ordering: isSet(object.ordering) ? orderFromJSON(object.ordering) : -1,
            connectionHops: Array.isArray(object?.connectionHops)
                ? object.connectionHops.map((e) => String(e))
                : [],
            version: isSet(object.version) ? String(object.version) : '',
        };
    },
    toJSON(message) {
        const obj = {};
        message.ordering !== undefined &&
            (obj.ordering = orderToJSON(message.ordering));
        if (message.connectionHops) {
            obj.connectionHops = message.connectionHops.map(e => e);
        }
        else {
            obj.connectionHops = [];
        }
        message.version !== undefined && (obj.version = message.version);
        return obj;
    },
    fromPartial(object) {
        const message = createBaseUpgradeFields();
        message.ordering = object.ordering ?? 0;
        message.connectionHops = object.connectionHops?.map(e => e) || [];
        message.version = object.version ?? '';
        return message;
    },
    fromProtoMsg(message) {
        return UpgradeFields.decode(message.value);
    },
    toProto(message) {
        return UpgradeFields.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/ibc.core.channel.v1.UpgradeFields',
            value: UpgradeFields.encode(message).finish(),
        };
    },
};
function createBaseErrorReceipt() {
    return {
        sequence: BigInt(0),
        message: '',
    };
}
export const ErrorReceipt = {
    typeUrl: '/ibc.core.channel.v1.ErrorReceipt',
    encode(message, writer = BinaryWriter.create()) {
        if (message.sequence !== BigInt(0)) {
            writer.uint32(8).uint64(message.sequence);
        }
        if (message.message !== '') {
            writer.uint32(18).string(message.message);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseErrorReceipt();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.sequence = reader.uint64();
                    break;
                case 2:
                    message.message = reader.string();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            sequence: isSet(object.sequence)
                ? BigInt(object.sequence.toString())
                : BigInt(0),
            message: isSet(object.message) ? String(object.message) : '',
        };
    },
    toJSON(message) {
        const obj = {};
        message.sequence !== undefined &&
            (obj.sequence = (message.sequence || BigInt(0)).toString());
        message.message !== undefined && (obj.message = message.message);
        return obj;
    },
    fromPartial(object) {
        const message = createBaseErrorReceipt();
        message.sequence =
            object.sequence !== undefined && object.sequence !== null
                ? BigInt(object.sequence.toString())
                : BigInt(0);
        message.message = object.message ?? '';
        return message;
    },
    fromProtoMsg(message) {
        return ErrorReceipt.decode(message.value);
    },
    toProto(message) {
        return ErrorReceipt.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/ibc.core.channel.v1.ErrorReceipt',
            value: ErrorReceipt.encode(message).finish(),
        };
    },
};
//# sourceMappingURL=upgrade.js.map