//@ts-nocheck
import { Timestamp, } from '../../../google/protobuf/timestamp.js';
import { BinaryReader, BinaryWriter } from '../../../binary.js';
import { isSet, fromJsonTimestamp, fromTimestamp } from '../../../helpers.js';
import {} from '../../../json-safe.js';
import { decodeBase64 as bytesFromBase64 } from '@endo/base64';
import { encodeBase64 as base64FromBytes } from '@endo/base64';
function createBaseCommitInfo() {
    return {
        version: BigInt(0),
        storeInfos: [],
        timestamp: Timestamp.fromPartial({}),
    };
}
export const CommitInfo = {
    typeUrl: '/cosmos.store.v1beta1.CommitInfo',
    encode(message, writer = BinaryWriter.create()) {
        if (message.version !== BigInt(0)) {
            writer.uint32(8).int64(message.version);
        }
        for (const v of message.storeInfos) {
            StoreInfo.encode(v, writer.uint32(18).fork()).ldelim();
        }
        if (message.timestamp !== undefined) {
            Timestamp.encode(message.timestamp, writer.uint32(26).fork()).ldelim();
        }
        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 = createBaseCommitInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.version = reader.int64();
                    break;
                case 2:
                    message.storeInfos.push(StoreInfo.decode(reader, reader.uint32()));
                    break;
                case 3:
                    message.timestamp = Timestamp.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            version: isSet(object.version)
                ? BigInt(object.version.toString())
                : BigInt(0),
            storeInfos: Array.isArray(object?.storeInfos)
                ? object.storeInfos.map((e) => StoreInfo.fromJSON(e))
                : [],
            timestamp: isSet(object.timestamp)
                ? fromJsonTimestamp(object.timestamp)
                : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        message.version !== undefined &&
            (obj.version = (message.version || BigInt(0)).toString());
        if (message.storeInfos) {
            obj.storeInfos = message.storeInfos.map(e => e ? StoreInfo.toJSON(e) : undefined);
        }
        else {
            obj.storeInfos = [];
        }
        message.timestamp !== undefined &&
            (obj.timestamp = fromTimestamp(message.timestamp).toISOString());
        return obj;
    },
    fromPartial(object) {
        const message = createBaseCommitInfo();
        message.version =
            object.version !== undefined && object.version !== null
                ? BigInt(object.version.toString())
                : BigInt(0);
        message.storeInfos =
            object.storeInfos?.map(e => StoreInfo.fromPartial(e)) || [];
        message.timestamp =
            object.timestamp !== undefined && object.timestamp !== null
                ? Timestamp.fromPartial(object.timestamp)
                : undefined;
        return message;
    },
    fromProtoMsg(message) {
        return CommitInfo.decode(message.value);
    },
    toProto(message) {
        return CommitInfo.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/cosmos.store.v1beta1.CommitInfo',
            value: CommitInfo.encode(message).finish(),
        };
    },
};
function createBaseStoreInfo() {
    return {
        name: '',
        commitId: CommitID.fromPartial({}),
    };
}
export const StoreInfo = {
    typeUrl: '/cosmos.store.v1beta1.StoreInfo',
    encode(message, writer = BinaryWriter.create()) {
        if (message.name !== '') {
            writer.uint32(10).string(message.name);
        }
        if (message.commitId !== undefined) {
            CommitID.encode(message.commitId, writer.uint32(18).fork()).ldelim();
        }
        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 = createBaseStoreInfo();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.name = reader.string();
                    break;
                case 2:
                    message.commitId = CommitID.decode(reader, reader.uint32());
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            name: isSet(object.name) ? String(object.name) : '',
            commitId: isSet(object.commitId)
                ? CommitID.fromJSON(object.commitId)
                : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        message.name !== undefined && (obj.name = message.name);
        message.commitId !== undefined &&
            (obj.commitId = message.commitId
                ? CommitID.toJSON(message.commitId)
                : undefined);
        return obj;
    },
    fromPartial(object) {
        const message = createBaseStoreInfo();
        message.name = object.name ?? '';
        message.commitId =
            object.commitId !== undefined && object.commitId !== null
                ? CommitID.fromPartial(object.commitId)
                : undefined;
        return message;
    },
    fromProtoMsg(message) {
        return StoreInfo.decode(message.value);
    },
    toProto(message) {
        return StoreInfo.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/cosmos.store.v1beta1.StoreInfo',
            value: StoreInfo.encode(message).finish(),
        };
    },
};
function createBaseCommitID() {
    return {
        version: BigInt(0),
        hash: new Uint8Array(),
    };
}
export const CommitID = {
    typeUrl: '/cosmos.store.v1beta1.CommitID',
    encode(message, writer = BinaryWriter.create()) {
        if (message.version !== BigInt(0)) {
            writer.uint32(8).int64(message.version);
        }
        if (message.hash.length !== 0) {
            writer.uint32(18).bytes(message.hash);
        }
        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 = createBaseCommitID();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.version = reader.int64();
                    break;
                case 2:
                    message.hash = reader.bytes();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromJSON(object) {
        return {
            version: isSet(object.version)
                ? BigInt(object.version.toString())
                : BigInt(0),
            hash: isSet(object.hash)
                ? bytesFromBase64(object.hash)
                : new Uint8Array(),
        };
    },
    toJSON(message) {
        const obj = {};
        message.version !== undefined &&
            (obj.version = (message.version || BigInt(0)).toString());
        message.hash !== undefined &&
            (obj.hash = base64FromBytes(message.hash !== undefined ? message.hash : new Uint8Array()));
        return obj;
    },
    fromPartial(object) {
        const message = createBaseCommitID();
        message.version =
            object.version !== undefined && object.version !== null
                ? BigInt(object.version.toString())
                : BigInt(0);
        message.hash = object.hash ?? new Uint8Array();
        return message;
    },
    fromProtoMsg(message) {
        return CommitID.decode(message.value);
    },
    toProto(message) {
        return CommitID.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: '/cosmos.store.v1beta1.CommitID',
            value: CommitID.encode(message).finish(),
        };
    },
};
//# sourceMappingURL=commit_info.js.map