/**
 * #app_publish_request_modmail.ts
 *
 * Code generated by ts-proto. DO NOT EDIT.
 * @packageDocumentation
 */
/* eslint-disable */
import _m0 from "protobufjs/minimal.js";
import { Timestamp } from "../../../../google/protobuf/timestamp.js";
import { messageTypeRegistry } from "../../../../typeRegistry.js";
import { appPublishRequestReviewDecisionFromJSON, appPublishRequestReviewDecisionToJSON, } from "../review/app_publish_request_review.js";
export var AppPRModmailConversationMatchType;
(function (AppPRModmailConversationMatchType) {
    AppPRModmailConversationMatchType[AppPRModmailConversationMatchType["APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_UNSPECIFIED"] = 0] = "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_UNSPECIFIED";
    AppPRModmailConversationMatchType[AppPRModmailConversationMatchType["APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_LINKED"] = 1] = "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_LINKED";
    AppPRModmailConversationMatchType[AppPRModmailConversationMatchType["APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_FALLBACK"] = 2] = "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_FALLBACK";
    AppPRModmailConversationMatchType[AppPRModmailConversationMatchType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(AppPRModmailConversationMatchType || (AppPRModmailConversationMatchType = {}));
export function appPRModmailConversationMatchTypeFromJSON(object) {
    switch (object) {
        case 0:
        case "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_UNSPECIFIED":
            return AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_UNSPECIFIED;
        case 1:
        case "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_LINKED":
            return AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_LINKED;
        case 2:
        case "APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_FALLBACK":
            return AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_FALLBACK;
        case -1:
        case "UNRECOGNIZED":
        default:
            return AppPRModmailConversationMatchType.UNRECOGNIZED;
    }
}
export function appPRModmailConversationMatchTypeToJSON(object) {
    switch (object) {
        case AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_UNSPECIFIED:
            return 0;
        case AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_LINKED:
            return 1;
        case AppPRModmailConversationMatchType.APP_PR_MODMAIL_CONVERSATION_MATCH_TYPE_FALLBACK:
            return 2;
        case AppPRModmailConversationMatchType.UNRECOGNIZED:
        default:
            return -1;
    }
}
function createBaseAppPRModmailMessagePreview() {
    return { authorDisplayName: "", bodyMarkdown: "", createdAt: undefined };
}
export const AppPRModmailMessagePreview = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRModmailMessagePreview",
    encode(message, writer = _m0.Writer.create()) {
        if (message.authorDisplayName !== "") {
            writer.uint32(10).string(message.authorDisplayName);
        }
        if (message.bodyMarkdown !== "") {
            writer.uint32(18).string(message.bodyMarkdown);
        }
        if (message.createdAt !== undefined) {
            Timestamp.encode(toTimestamp(message.createdAt), 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 = createBaseAppPRModmailMessagePreview();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.authorDisplayName = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.bodyMarkdown = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.createdAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            authorDisplayName: isSet(object.authorDisplayName) ? globalThis.String(object.authorDisplayName) : "",
            bodyMarkdown: isSet(object.bodyMarkdown) ? globalThis.String(object.bodyMarkdown) : "",
            createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.authorDisplayName !== "") {
            obj.authorDisplayName = message.authorDisplayName;
        }
        if (message.bodyMarkdown !== "") {
            obj.bodyMarkdown = message.bodyMarkdown;
        }
        if (message.createdAt !== undefined) {
            obj.createdAt = message.createdAt.toISOString();
        }
        return obj;
    },
    create(base) {
        return AppPRModmailMessagePreview.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRModmailMessagePreview();
        message.authorDisplayName = object.authorDisplayName ?? "";
        message.bodyMarkdown = object.bodyMarkdown ?? "";
        message.createdAt = object.createdAt ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(AppPRModmailMessagePreview.$type, AppPRModmailMessagePreview);
function createBaseAppPRModmailConversation() {
    return {
        conversationId: "",
        subject: "",
        lastMessageCreatedAt: undefined,
        lastMessageMarkdown: "",
        matchType: 0,
        messagePreviews: [],
    };
}
export const AppPRModmailConversation = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRModmailConversation",
    encode(message, writer = _m0.Writer.create()) {
        if (message.conversationId !== "") {
            writer.uint32(10).string(message.conversationId);
        }
        if (message.subject !== "") {
            writer.uint32(18).string(message.subject);
        }
        if (message.lastMessageCreatedAt !== undefined) {
            Timestamp.encode(toTimestamp(message.lastMessageCreatedAt), writer.uint32(26).fork()).ldelim();
        }
        if (message.lastMessageMarkdown !== "") {
            writer.uint32(34).string(message.lastMessageMarkdown);
        }
        if (message.matchType !== 0) {
            writer.uint32(40).int32(message.matchType);
        }
        for (const v of message.messagePreviews) {
            AppPRModmailMessagePreview.encode(v, writer.uint32(50).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 = createBaseAppPRModmailConversation();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.conversationId = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.subject = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.lastMessageCreatedAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.lastMessageMarkdown = reader.string();
                    continue;
                case 5:
                    if (tag !== 40) {
                        break;
                    }
                    message.matchType = reader.int32();
                    continue;
                case 6:
                    if (tag !== 50) {
                        break;
                    }
                    message.messagePreviews.push(AppPRModmailMessagePreview.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            conversationId: isSet(object.conversationId) ? globalThis.String(object.conversationId) : "",
            subject: isSet(object.subject) ? globalThis.String(object.subject) : "",
            lastMessageCreatedAt: isSet(object.lastMessageCreatedAt)
                ? fromJsonTimestamp(object.lastMessageCreatedAt)
                : undefined,
            lastMessageMarkdown: isSet(object.lastMessageMarkdown) ? globalThis.String(object.lastMessageMarkdown) : "",
            matchType: isSet(object.matchType) ? appPRModmailConversationMatchTypeFromJSON(object.matchType) : 0,
            messagePreviews: globalThis.Array.isArray(object?.messagePreviews)
                ? object.messagePreviews.map((e) => AppPRModmailMessagePreview.fromJSON(e))
                : [],
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.conversationId !== "") {
            obj.conversationId = message.conversationId;
        }
        if (message.subject !== "") {
            obj.subject = message.subject;
        }
        if (message.lastMessageCreatedAt !== undefined) {
            obj.lastMessageCreatedAt = message.lastMessageCreatedAt.toISOString();
        }
        if (message.lastMessageMarkdown !== "") {
            obj.lastMessageMarkdown = message.lastMessageMarkdown;
        }
        if (message.matchType !== 0) {
            obj.matchType = appPRModmailConversationMatchTypeToJSON(message.matchType);
        }
        if (message.messagePreviews?.length) {
            obj.messagePreviews = message.messagePreviews.map((e) => AppPRModmailMessagePreview.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return AppPRModmailConversation.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRModmailConversation();
        message.conversationId = object.conversationId ?? "";
        message.subject = object.subject ?? "";
        message.lastMessageCreatedAt = object.lastMessageCreatedAt ?? undefined;
        message.lastMessageMarkdown = object.lastMessageMarkdown ?? "";
        message.matchType = object.matchType ?? 0;
        message.messagePreviews = object.messagePreviews?.map((e) => AppPRModmailMessagePreview.fromPartial(e)) || [];
        return message;
    },
};
messageTypeRegistry.set(AppPRModmailConversation.$type, AppPRModmailConversation);
function createBaseAppPRListModmailConversationsRequest() {
    return {
        appPublishRequestId: "",
        maxConversations: 0,
        maxMessagePreviewsPerConversation: 0,
        includeFallbackMatches: false,
    };
}
export const AppPRListModmailConversationsRequest = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRListModmailConversationsRequest",
    encode(message, writer = _m0.Writer.create()) {
        if (message.appPublishRequestId !== "") {
            writer.uint32(10).string(message.appPublishRequestId);
        }
        if (message.maxConversations !== 0) {
            writer.uint32(16).int32(message.maxConversations);
        }
        if (message.maxMessagePreviewsPerConversation !== 0) {
            writer.uint32(24).int32(message.maxMessagePreviewsPerConversation);
        }
        if (message.includeFallbackMatches !== false) {
            writer.uint32(32).bool(message.includeFallbackMatches);
        }
        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 = createBaseAppPRListModmailConversationsRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.appPublishRequestId = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.maxConversations = reader.int32();
                    continue;
                case 3:
                    if (tag !== 24) {
                        break;
                    }
                    message.maxMessagePreviewsPerConversation = reader.int32();
                    continue;
                case 4:
                    if (tag !== 32) {
                        break;
                    }
                    message.includeFallbackMatches = reader.bool();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            appPublishRequestId: isSet(object.appPublishRequestId) ? globalThis.String(object.appPublishRequestId) : "",
            maxConversations: isSet(object.maxConversations) ? globalThis.Number(object.maxConversations) : 0,
            maxMessagePreviewsPerConversation: isSet(object.maxMessagePreviewsPerConversation)
                ? globalThis.Number(object.maxMessagePreviewsPerConversation)
                : 0,
            includeFallbackMatches: isSet(object.includeFallbackMatches)
                ? globalThis.Boolean(object.includeFallbackMatches)
                : false,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.appPublishRequestId !== "") {
            obj.appPublishRequestId = message.appPublishRequestId;
        }
        if (message.maxConversations !== 0) {
            obj.maxConversations = Math.round(message.maxConversations);
        }
        if (message.maxMessagePreviewsPerConversation !== 0) {
            obj.maxMessagePreviewsPerConversation = Math.round(message.maxMessagePreviewsPerConversation);
        }
        if (message.includeFallbackMatches !== false) {
            obj.includeFallbackMatches = message.includeFallbackMatches;
        }
        return obj;
    },
    create(base) {
        return AppPRListModmailConversationsRequest.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRListModmailConversationsRequest();
        message.appPublishRequestId = object.appPublishRequestId ?? "";
        message.maxConversations = object.maxConversations ?? 0;
        message.maxMessagePreviewsPerConversation = object.maxMessagePreviewsPerConversation ?? 0;
        message.includeFallbackMatches = object.includeFallbackMatches ?? false;
        return message;
    },
};
messageTypeRegistry.set(AppPRListModmailConversationsRequest.$type, AppPRListModmailConversationsRequest);
function createBaseAppPRListModmailConversationsResponse() {
    return { conversations: [] };
}
export const AppPRListModmailConversationsResponse = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRListModmailConversationsResponse",
    encode(message, writer = _m0.Writer.create()) {
        for (const v of message.conversations) {
            AppPRModmailConversation.encode(v, writer.uint32(10).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 = createBaseAppPRListModmailConversationsResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.conversations.push(AppPRModmailConversation.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            conversations: globalThis.Array.isArray(object?.conversations)
                ? object.conversations.map((e) => AppPRModmailConversation.fromJSON(e))
                : [],
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.conversations?.length) {
            obj.conversations = message.conversations.map((e) => AppPRModmailConversation.toJSON(e));
        }
        return obj;
    },
    create(base) {
        return AppPRListModmailConversationsResponse.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRListModmailConversationsResponse();
        message.conversations = object.conversations?.map((e) => AppPRModmailConversation.fromPartial(e)) || [];
        return message;
    },
};
messageTypeRegistry.set(AppPRListModmailConversationsResponse.$type, AppPRListModmailConversationsResponse);
function createBaseAppPRSetReviewDecisionWithModmailRequest() {
    return { appPublishRequestId: "", decision: 0, subject: "", bodyMarkdown: "", sendAsModTeam: false };
}
export const AppPRSetReviewDecisionWithModmailRequest = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRSetReviewDecisionWithModmailRequest",
    encode(message, writer = _m0.Writer.create()) {
        if (message.appPublishRequestId !== "") {
            writer.uint32(10).string(message.appPublishRequestId);
        }
        if (message.decision !== 0) {
            writer.uint32(16).int32(message.decision);
        }
        if (message.subject !== "") {
            writer.uint32(26).string(message.subject);
        }
        if (message.bodyMarkdown !== "") {
            writer.uint32(34).string(message.bodyMarkdown);
        }
        if (message.sendAsModTeam !== false) {
            writer.uint32(40).bool(message.sendAsModTeam);
        }
        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 = createBaseAppPRSetReviewDecisionWithModmailRequest();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.appPublishRequestId = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.decision = reader.int32();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.subject = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.bodyMarkdown = reader.string();
                    continue;
                case 5:
                    if (tag !== 40) {
                        break;
                    }
                    message.sendAsModTeam = reader.bool();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            appPublishRequestId: isSet(object.appPublishRequestId) ? globalThis.String(object.appPublishRequestId) : "",
            decision: isSet(object.decision) ? appPublishRequestReviewDecisionFromJSON(object.decision) : 0,
            subject: isSet(object.subject) ? globalThis.String(object.subject) : "",
            bodyMarkdown: isSet(object.bodyMarkdown) ? globalThis.String(object.bodyMarkdown) : "",
            sendAsModTeam: isSet(object.sendAsModTeam) ? globalThis.Boolean(object.sendAsModTeam) : false,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.appPublishRequestId !== "") {
            obj.appPublishRequestId = message.appPublishRequestId;
        }
        if (message.decision !== 0) {
            obj.decision = appPublishRequestReviewDecisionToJSON(message.decision);
        }
        if (message.subject !== "") {
            obj.subject = message.subject;
        }
        if (message.bodyMarkdown !== "") {
            obj.bodyMarkdown = message.bodyMarkdown;
        }
        if (message.sendAsModTeam !== false) {
            obj.sendAsModTeam = message.sendAsModTeam;
        }
        return obj;
    },
    create(base) {
        return AppPRSetReviewDecisionWithModmailRequest.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRSetReviewDecisionWithModmailRequest();
        message.appPublishRequestId = object.appPublishRequestId ?? "";
        message.decision = object.decision ?? 0;
        message.subject = object.subject ?? "";
        message.bodyMarkdown = object.bodyMarkdown ?? "";
        message.sendAsModTeam = object.sendAsModTeam ?? false;
        return message;
    },
};
messageTypeRegistry.set(AppPRSetReviewDecisionWithModmailRequest.$type, AppPRSetReviewDecisionWithModmailRequest);
function createBaseAppPRSetReviewDecisionWithModmailResponse() {
    return { modmailConversationId: "", noteAdded: false };
}
export const AppPRSetReviewDecisionWithModmailResponse = {
    $type: "devvit.dev_portal.app_publish_request.modmail.AppPRSetReviewDecisionWithModmailResponse",
    encode(message, writer = _m0.Writer.create()) {
        if (message.modmailConversationId !== "") {
            writer.uint32(10).string(message.modmailConversationId);
        }
        if (message.noteAdded !== false) {
            writer.uint32(16).bool(message.noteAdded);
        }
        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 = createBaseAppPRSetReviewDecisionWithModmailResponse();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.modmailConversationId = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.noteAdded = reader.bool();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            modmailConversationId: isSet(object.modmailConversationId) ? globalThis.String(object.modmailConversationId) : "",
            noteAdded: isSet(object.noteAdded) ? globalThis.Boolean(object.noteAdded) : false,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.modmailConversationId !== "") {
            obj.modmailConversationId = message.modmailConversationId;
        }
        if (message.noteAdded !== false) {
            obj.noteAdded = message.noteAdded;
        }
        return obj;
    },
    create(base) {
        return AppPRSetReviewDecisionWithModmailResponse.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseAppPRSetReviewDecisionWithModmailResponse();
        message.modmailConversationId = object.modmailConversationId ?? "";
        message.noteAdded = object.noteAdded ?? false;
        return message;
    },
};
messageTypeRegistry.set(AppPRSetReviewDecisionWithModmailResponse.$type, AppPRSetReviewDecisionWithModmailResponse);
function toTimestamp(date) {
    const seconds = Math.trunc(date.getTime() / 1000);
    const nanos = (date.getTime() % 1000) * 1000000;
    return { seconds, nanos };
}
function fromTimestamp(t) {
    let millis = (t.seconds || 0) * 1000;
    millis += (t.nanos || 0) / 1000000;
    return new globalThis.Date(millis);
}
function fromJsonTimestamp(o) {
    if (o instanceof globalThis.Date) {
        return o;
    }
    else if (typeof o === "string") {
        return new globalThis.Date(o);
    }
    else {
        return fromTimestamp(Timestamp.fromJSON(o));
    }
}
function isSet(value) {
    return value !== null && value !== undefined;
}
