import { Timestamp } from "../../../google/protobuf/timestamp";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { Decimal } from "@interchainjs/math";
import { toTimestamp, fromTimestamp } from "../../../helpers";
function createBaseContinuousFund() {
    return {
        recipient: "",
        percentage: "",
        expiry: undefined
    };
}
/**
 * ContinuousFund defines the fields of continuous fund proposal.
 * @name ContinuousFund
 * @package cosmos.protocolpool.v1
 * @see proto type: cosmos.protocolpool.v1.ContinuousFund
 */
export const ContinuousFund = {
    typeUrl: "/cosmos.protocolpool.v1.ContinuousFund",
    aminoType: "cosmos-sdk/ContinuousFund",
    is(o) {
        return o && (o.$typeUrl === ContinuousFund.typeUrl || typeof o.recipient === "string" && typeof o.percentage === "string");
    },
    isAmino(o) {
        return o && (o.$typeUrl === ContinuousFund.typeUrl || typeof o.recipient === "string" && typeof o.percentage === "string");
    },
    encode(message, writer = BinaryWriter.create()) {
        if (message.recipient !== "") {
            writer.uint32(10).string(message.recipient);
        }
        if (message.percentage !== "") {
            writer.uint32(18).string(Decimal.fromUserInput(message.percentage, 18).atomics);
        }
        if (message.expiry !== undefined) {
            Timestamp.encode(toTimestamp(message.expiry), 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 = createBaseContinuousFund();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.recipient = reader.string();
                    break;
                case 2:
                    message.percentage = Decimal.fromAtomics(reader.string(), 18).toString();
                    break;
                case 3:
                    message.expiry = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseContinuousFund();
        message.recipient = object.recipient ?? "";
        message.percentage = object.percentage ?? "";
        message.expiry = object.expiry ?? undefined;
        return message;
    },
    fromAmino(object) {
        const message = createBaseContinuousFund();
        if (object.recipient !== undefined && object.recipient !== null) {
            message.recipient = object.recipient;
        }
        if (object.percentage !== undefined && object.percentage !== null) {
            message.percentage = object.percentage;
        }
        if (object.expiry !== undefined && object.expiry !== null) {
            message.expiry = fromTimestamp(Timestamp.fromAmino(object.expiry));
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        obj.recipient = message.recipient === "" ? undefined : message.recipient;
        obj.percentage = message.percentage === "" ? undefined : Decimal.fromUserInput(message.percentage, 18).atomics;
        obj.expiry = message.expiry ? Timestamp.toAmino(toTimestamp(message.expiry)) : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return ContinuousFund.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/ContinuousFund",
            value: ContinuousFund.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return ContinuousFund.decode(message.value);
    },
    toProto(message) {
        return ContinuousFund.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.protocolpool.v1.ContinuousFund",
            value: ContinuousFund.encode(message).finish()
        };
    },
    registerTypeUrl() { }
};
function createBaseParams() {
    return {
        enabledDistributionDenoms: [],
        distributionFrequency: BigInt(0)
    };
}
/**
 * Params defines the parameters for the protocolpool module.
 * @name Params
 * @package cosmos.protocolpool.v1
 * @see proto type: cosmos.protocolpool.v1.Params
 */
export const Params = {
    typeUrl: "/cosmos.protocolpool.v1.Params",
    aminoType: "cosmos-sdk/Params",
    is(o) {
        return o && (o.$typeUrl === Params.typeUrl || Array.isArray(o.enabledDistributionDenoms) && (!o.enabledDistributionDenoms.length || typeof o.enabledDistributionDenoms[0] === "string") && typeof o.distributionFrequency === "bigint");
    },
    isAmino(o) {
        return o && (o.$typeUrl === Params.typeUrl || Array.isArray(o.enabled_distribution_denoms) && (!o.enabled_distribution_denoms.length || typeof o.enabled_distribution_denoms[0] === "string") && typeof o.distribution_frequency === "bigint");
    },
    encode(message, writer = BinaryWriter.create()) {
        for (const v of message.enabledDistributionDenoms) {
            writer.uint32(10).string(v);
        }
        if (message.distributionFrequency !== BigInt(0)) {
            writer.uint32(16).uint64(message.distributionFrequency);
        }
        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 = createBaseParams();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.enabledDistributionDenoms.push(reader.string());
                    break;
                case 2:
                    message.distributionFrequency = reader.uint64();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        return message;
    },
    fromPartial(object) {
        const message = createBaseParams();
        message.enabledDistributionDenoms = object.enabledDistributionDenoms?.map(e => e) || [];
        message.distributionFrequency = object.distributionFrequency !== undefined && object.distributionFrequency !== null ? BigInt(object.distributionFrequency.toString()) : BigInt(0);
        return message;
    },
    fromAmino(object) {
        const message = createBaseParams();
        message.enabledDistributionDenoms = object.enabled_distribution_denoms?.map(e => e) || [];
        if (object.distribution_frequency !== undefined && object.distribution_frequency !== null) {
            message.distributionFrequency = BigInt(object.distribution_frequency);
        }
        return message;
    },
    toAmino(message) {
        const obj = {};
        if (message.enabledDistributionDenoms) {
            obj.enabled_distribution_denoms = message.enabledDistributionDenoms.map(e => e);
        }
        else {
            obj.enabled_distribution_denoms = message.enabledDistributionDenoms;
        }
        obj.distribution_frequency = message.distributionFrequency !== BigInt(0) ? message.distributionFrequency?.toString() : undefined;
        return obj;
    },
    fromAminoMsg(object) {
        return Params.fromAmino(object.value);
    },
    toAminoMsg(message) {
        return {
            type: "cosmos-sdk/Params",
            value: Params.toAmino(message)
        };
    },
    fromProtoMsg(message) {
        return Params.decode(message.value);
    },
    toProto(message) {
        return Params.encode(message).finish();
    },
    toProtoMsg(message) {
        return {
            typeUrl: "/cosmos.protocolpool.v1.Params",
            value: Params.encode(message).finish()
        };
    },
    registerTypeUrl() { }
};
