/**
 * #telemetry.ts
 *
 * Code generated by ts-proto. DO NOT EDIT.
 * @packageDocumentation
 */
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal.js";
import { messageTypeRegistry } from "../../../typeRegistry.js";
function createBaseStartJourneyRequest() {
    return {};
}
export const StartJourneyRequest = {
    $type: "devvit.plugin.telemetry.StartJourneyRequest",
    encode(_, writer = _m0.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseStartJourneyRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(_) {
        return {};
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    create(base) {
        return StartJourneyRequest.fromPartial(base ?? {});
    },
    fromPartial(_) {
        const message = createBaseStartJourneyRequest();
        return message;
    },
};
messageTypeRegistry.set(StartJourneyRequest.$type, StartJourneyRequest);
function createBaseStartJourneyResponse() {
    return { journeyId: "" };
}
export const StartJourneyResponse = {
    $type: "devvit.plugin.telemetry.StartJourneyResponse",
    encode(message, writer = _m0.Writer.create()) {
        if (message.journeyId !== "") {
            writer.uint32(10).string(message.journeyId);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseStartJourneyResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.journeyId = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { journeyId: isSet(object.journeyId) ? globalThis.String(object.journeyId) : "" };
    },
    toJSON(message) {
        const obj = {};
        if (message.journeyId !== "") {
            obj.journeyId = message.journeyId;
        }
        return obj;
    },
    create(base) {
        return StartJourneyResponse.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseStartJourneyResponse();
        message.journeyId = object.journeyId ?? "";
        return message;
    },
};
messageTypeRegistry.set(StartJourneyResponse.$type, StartJourneyResponse);
function createBaseJourneyProgressRequest() {
    return { journeyId: "", progress: 0, action: undefined, actionDetails: undefined };
}
export const JourneyProgressRequest = {
    $type: "devvit.plugin.telemetry.JourneyProgressRequest",
    encode(message, writer = _m0.Writer.create()) {
        if (message.journeyId !== "") {
            writer.uint32(10).string(message.journeyId);
        }
        if (message.progress !== 0) {
            writer.uint32(21).float(message.progress);
        }
        if (message.action !== undefined) {
            writer.uint32(26).string(message.action);
        }
        if (message.actionDetails !== undefined) {
            writer.uint32(34).string(message.actionDetails);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseJourneyProgressRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.journeyId = reader.string();
                    continue;
                case 2:
                    if (tag !== 21) {
                        break;
                    }
                    message.progress = reader.float();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.action = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.actionDetails = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            journeyId: isSet(object.journeyId) ? globalThis.String(object.journeyId) : "",
            progress: isSet(object.progress) ? globalThis.Number(object.progress) : 0,
            action: isSet(object.action) ? globalThis.String(object.action) : undefined,
            actionDetails: isSet(object.actionDetails) ? globalThis.String(object.actionDetails) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.journeyId !== "") {
            obj.journeyId = message.journeyId;
        }
        if (message.progress !== 0) {
            obj.progress = message.progress;
        }
        if (message.action !== undefined) {
            obj.action = message.action;
        }
        if (message.actionDetails !== undefined) {
            obj.actionDetails = message.actionDetails;
        }
        return obj;
    },
    create(base) {
        return JourneyProgressRequest.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseJourneyProgressRequest();
        message.journeyId = object.journeyId ?? "";
        message.progress = object.progress ?? 0;
        message.action = object.action ?? undefined;
        message.actionDetails = object.actionDetails ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(JourneyProgressRequest.$type, JourneyProgressRequest);
function createBaseJourneyProgressResponse() {
    return {};
}
export const JourneyProgressResponse = {
    $type: "devvit.plugin.telemetry.JourneyProgressResponse",
    encode(_, writer = _m0.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseJourneyProgressResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(_) {
        return {};
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    create(base) {
        return JourneyProgressResponse.fromPartial(base ?? {});
    },
    fromPartial(_) {
        const message = createBaseJourneyProgressResponse();
        return message;
    },
};
messageTypeRegistry.set(JourneyProgressResponse.$type, JourneyProgressResponse);
function createBaseJourneyInteractionRequest() {
    return { journeyId: "", action: "", actionDetails: "" };
}
export const JourneyInteractionRequest = {
    $type: "devvit.plugin.telemetry.JourneyInteractionRequest",
    encode(message, writer = _m0.Writer.create()) {
        if (message.journeyId !== "") {
            writer.uint32(10).string(message.journeyId);
        }
        if (message.action !== "") {
            writer.uint32(18).string(message.action);
        }
        if (message.actionDetails !== "") {
            writer.uint32(26).string(message.actionDetails);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseJourneyInteractionRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.journeyId = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.action = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.actionDetails = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            journeyId: isSet(object.journeyId) ? globalThis.String(object.journeyId) : "",
            action: isSet(object.action) ? globalThis.String(object.action) : "",
            actionDetails: isSet(object.actionDetails) ? globalThis.String(object.actionDetails) : "",
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.journeyId !== "") {
            obj.journeyId = message.journeyId;
        }
        if (message.action !== "") {
            obj.action = message.action;
        }
        if (message.actionDetails !== "") {
            obj.actionDetails = message.actionDetails;
        }
        return obj;
    },
    create(base) {
        return JourneyInteractionRequest.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseJourneyInteractionRequest();
        message.journeyId = object.journeyId ?? "";
        message.action = object.action ?? "";
        message.actionDetails = object.actionDetails ?? "";
        return message;
    },
};
messageTypeRegistry.set(JourneyInteractionRequest.$type, JourneyInteractionRequest);
function createBaseJourneyInteractionResponse() {
    return {};
}
export const JourneyInteractionResponse = {
    $type: "devvit.plugin.telemetry.JourneyInteractionResponse",
    encode(_, writer = _m0.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseJourneyInteractionResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(_) {
        return {};
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    create(base) {
        return JourneyInteractionResponse.fromPartial(base ?? {});
    },
    fromPartial(_) {
        const message = createBaseJourneyInteractionResponse();
        return message;
    },
};
messageTypeRegistry.set(JourneyInteractionResponse.$type, JourneyInteractionResponse);
function createBaseGameResult() {
    return { win: false, score: 0 };
}
export const GameResult = {
    $type: "devvit.plugin.telemetry.GameResult",
    encode(message, writer = _m0.Writer.create()) {
        if (message.win !== false) {
            writer.uint32(8).bool(message.win);
        }
        if (message.score !== 0) {
            writer.uint32(16).int64(message.score);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseGameResult();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 8) {
                        break;
                    }
                    message.win = reader.bool();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.score = longToNumber(reader.int64());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            win: isSet(object.win) ? globalThis.Boolean(object.win) : false,
            score: isSet(object.score) ? globalThis.Number(object.score) : 0,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.win !== false) {
            obj.win = message.win;
        }
        if (message.score !== 0) {
            obj.score = Math.round(message.score);
        }
        return obj;
    },
    create(base) {
        return GameResult.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseGameResult();
        message.win = object.win ?? false;
        message.score = object.score ?? 0;
        return message;
    },
};
messageTypeRegistry.set(GameResult.$type, GameResult);
function createBaseEndJourneyRequest() {
    return { journeyId: "", complete: false, game: undefined };
}
export const EndJourneyRequest = {
    $type: "devvit.plugin.telemetry.EndJourneyRequest",
    encode(message, writer = _m0.Writer.create()) {
        if (message.journeyId !== "") {
            writer.uint32(10).string(message.journeyId);
        }
        if (message.complete !== false) {
            writer.uint32(16).bool(message.complete);
        }
        if (message.game !== undefined) {
            GameResult.encode(message.game, writer.uint32(26).fork()).ldelim();
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseEndJourneyRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.journeyId = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.complete = reader.bool();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.game = GameResult.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            journeyId: isSet(object.journeyId) ? globalThis.String(object.journeyId) : "",
            complete: isSet(object.complete) ? globalThis.Boolean(object.complete) : false,
            game: isSet(object.game) ? GameResult.fromJSON(object.game) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.journeyId !== "") {
            obj.journeyId = message.journeyId;
        }
        if (message.complete !== false) {
            obj.complete = message.complete;
        }
        if (message.game !== undefined) {
            obj.game = GameResult.toJSON(message.game);
        }
        return obj;
    },
    create(base) {
        return EndJourneyRequest.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseEndJourneyRequest();
        message.journeyId = object.journeyId ?? "";
        message.complete = object.complete ?? false;
        message.game = (object.game !== undefined && object.game !== null)
            ? GameResult.fromPartial(object.game)
            : undefined;
        return message;
    },
};
messageTypeRegistry.set(EndJourneyRequest.$type, EndJourneyRequest);
function createBaseEndJourneyResponse() {
    return {};
}
export const EndJourneyResponse = {
    $type: "devvit.plugin.telemetry.EndJourneyResponse",
    encode(_, writer = _m0.Writer.create()) {
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
        let end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseEndJourneyResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(_) {
        return {};
    },
    toJSON(_) {
        const obj = {};
        return obj;
    },
    create(base) {
        return EndJourneyResponse.fromPartial(base ?? {});
    },
    fromPartial(_) {
        const message = createBaseEndJourneyResponse();
        return message;
    },
};
messageTypeRegistry.set(EndJourneyResponse.$type, EndJourneyResponse);
export const TelemetryPluginServiceName = "devvit.plugin.telemetry.TelemetryPlugin";
export class TelemetryPluginClientImpl {
    constructor(rpc, opts) {
        this.service = opts?.service || TelemetryPluginServiceName;
        this.rpc = rpc;
        this.StartJourney = this.StartJourney.bind(this);
        this.JourneyProgress = this.JourneyProgress.bind(this);
        this.JourneyInteraction = this.JourneyInteraction.bind(this);
        this.EndJourney = this.EndJourney.bind(this);
    }
    StartJourney(request, metadata) {
        const data = StartJourneyRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "StartJourney", data, metadata);
        return promise.then((data) => StartJourneyResponse.decode(_m0.Reader.create(data)));
    }
    JourneyProgress(request, metadata) {
        const data = JourneyProgressRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "JourneyProgress", data, metadata);
        return promise.then((data) => JourneyProgressResponse.decode(_m0.Reader.create(data)));
    }
    JourneyInteraction(request, metadata) {
        const data = JourneyInteractionRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "JourneyInteraction", data, metadata);
        return promise.then((data) => JourneyInteractionResponse.decode(_m0.Reader.create(data)));
    }
    EndJourney(request, metadata) {
        const data = EndJourneyRequest.encode(request).finish();
        const promise = this.rpc.request(this.service, "EndJourney", data, metadata);
        return promise.then((data) => EndJourneyResponse.decode(_m0.Reader.create(data)));
    }
}
export const TelemetryPluginDefinition = {
    name: "TelemetryPlugin",
    fullName: "devvit.plugin.telemetry.TelemetryPlugin",
    methods: {
        /** Starts a new telemetry journey. */
        startJourney: {
            name: "StartJourney",
            requestType: StartJourneyRequest,
            requestStream: false,
            responseType: StartJourneyResponse,
            responseStream: false,
            options: {},
        },
        /** Records progress within a journey. */
        journeyProgress: {
            name: "JourneyProgress",
            requestType: JourneyProgressRequest,
            requestStream: false,
            responseType: JourneyProgressResponse,
            responseStream: false,
            options: {},
        },
        /** Records an interaction within a journey. */
        journeyInteraction: {
            name: "JourneyInteraction",
            requestType: JourneyInteractionRequest,
            requestStream: false,
            responseType: JourneyInteractionResponse,
            responseStream: false,
            options: {},
        },
        /** Ends a telemetry journey. */
        endJourney: {
            name: "EndJourney",
            requestType: EndJourneyRequest,
            requestStream: false,
            responseType: EndJourneyResponse,
            responseStream: false,
            options: {},
        },
    },
};
function longToNumber(long) {
    if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
        throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
    }
    return long.toNumber();
}
if (_m0.util.Long !== Long) {
    _m0.util.Long = Long;
    _m0.configure();
}
function isSet(value) {
    return value !== null && value !== undefined;
}
