/**
 * #commentv2.ts
 *
 * @packageDocumentation
 */
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal.js";
import { messageTypeRegistry } from "../../../typeRegistry.js";
function createBaseCommentV2() {
    return {
        id: "",
        parentId: "",
        body: "",
        author: "",
        numReports: 0,
        collapsedBecauseCrowdControl: false,
        spam: false,
        deleted: false,
        createdAt: 0,
        upvotes: 0,
        downvotes: 0,
        languageCode: "",
        lastModifiedAt: 0,
        gilded: false,
        score: 0,
        permalink: "",
        hasMedia: false,
        postId: "",
        subredditId: "",
        elementTypes: [],
        mediaUrls: [],
    };
}
export const CommentV2 = {
    $type: "devvit.reddit.v2alpha.CommentV2",
    encode(message, writer = _m0.Writer.create()) {
        if (message.id !== "") {
            writer.uint32(10).string(message.id);
        }
        if (message.parentId !== "") {
            writer.uint32(18).string(message.parentId);
        }
        if (message.body !== "") {
            writer.uint32(26).string(message.body);
        }
        if (message.author !== "") {
            writer.uint32(34).string(message.author);
        }
        if (message.numReports !== 0) {
            writer.uint32(40).int32(message.numReports);
        }
        if (message.collapsedBecauseCrowdControl !== false) {
            writer.uint32(48).bool(message.collapsedBecauseCrowdControl);
        }
        if (message.spam !== false) {
            writer.uint32(56).bool(message.spam);
        }
        if (message.deleted !== false) {
            writer.uint32(64).bool(message.deleted);
        }
        if (message.createdAt !== 0) {
            writer.uint32(72).int64(message.createdAt);
        }
        if (message.upvotes !== 0) {
            writer.uint32(80).int32(message.upvotes);
        }
        if (message.downvotes !== 0) {
            writer.uint32(88).int32(message.downvotes);
        }
        if (message.languageCode !== "") {
            writer.uint32(98).string(message.languageCode);
        }
        if (message.lastModifiedAt !== 0) {
            writer.uint32(104).int64(message.lastModifiedAt);
        }
        if (message.gilded !== false) {
            writer.uint32(112).bool(message.gilded);
        }
        if (message.score !== 0) {
            writer.uint32(120).int32(message.score);
        }
        if (message.permalink !== "") {
            writer.uint32(130).string(message.permalink);
        }
        if (message.hasMedia !== false) {
            writer.uint32(136).bool(message.hasMedia);
        }
        if (message.postId !== "") {
            writer.uint32(146).string(message.postId);
        }
        if (message.subredditId !== "") {
            writer.uint32(154).string(message.subredditId);
        }
        for (const v of message.elementTypes) {
            writer.uint32(162).string(v);
        }
        for (const v of message.mediaUrls) {
            writer.uint32(170).string(v);
        }
        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 = createBaseCommentV2();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.parentId = reader.string();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.body = reader.string();
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.author = reader.string();
                    continue;
                case 5:
                    if (tag !== 40) {
                        break;
                    }
                    message.numReports = reader.int32();
                    continue;
                case 6:
                    if (tag !== 48) {
                        break;
                    }
                    message.collapsedBecauseCrowdControl = reader.bool();
                    continue;
                case 7:
                    if (tag !== 56) {
                        break;
                    }
                    message.spam = reader.bool();
                    continue;
                case 8:
                    if (tag !== 64) {
                        break;
                    }
                    message.deleted = reader.bool();
                    continue;
                case 9:
                    if (tag !== 72) {
                        break;
                    }
                    message.createdAt = longToNumber(reader.int64());
                    continue;
                case 10:
                    if (tag !== 80) {
                        break;
                    }
                    message.upvotes = reader.int32();
                    continue;
                case 11:
                    if (tag !== 88) {
                        break;
                    }
                    message.downvotes = reader.int32();
                    continue;
                case 12:
                    if (tag !== 98) {
                        break;
                    }
                    message.languageCode = reader.string();
                    continue;
                case 13:
                    if (tag !== 104) {
                        break;
                    }
                    message.lastModifiedAt = longToNumber(reader.int64());
                    continue;
                case 14:
                    if (tag !== 112) {
                        break;
                    }
                    message.gilded = reader.bool();
                    continue;
                case 15:
                    if (tag !== 120) {
                        break;
                    }
                    message.score = reader.int32();
                    continue;
                case 16:
                    if (tag !== 130) {
                        break;
                    }
                    message.permalink = reader.string();
                    continue;
                case 17:
                    if (tag !== 136) {
                        break;
                    }
                    message.hasMedia = reader.bool();
                    continue;
                case 18:
                    if (tag !== 146) {
                        break;
                    }
                    message.postId = reader.string();
                    continue;
                case 19:
                    if (tag !== 154) {
                        break;
                    }
                    message.subredditId = reader.string();
                    continue;
                case 20:
                    if (tag !== 162) {
                        break;
                    }
                    message.elementTypes.push(reader.string());
                    continue;
                case 21:
                    if (tag !== 170) {
                        break;
                    }
                    message.mediaUrls.push(reader.string());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            id: isSet(object.id) ? globalThis.String(object.id) : "",
            parentId: isSet(object.parentId) ? globalThis.String(object.parentId) : "",
            body: isSet(object.body) ? globalThis.String(object.body) : "",
            author: isSet(object.author) ? globalThis.String(object.author) : "",
            numReports: isSet(object.numReports) ? globalThis.Number(object.numReports) : 0,
            collapsedBecauseCrowdControl: isSet(object.collapsedBecauseCrowdControl)
                ? globalThis.Boolean(object.collapsedBecauseCrowdControl)
                : false,
            spam: isSet(object.spam) ? globalThis.Boolean(object.spam) : false,
            deleted: isSet(object.deleted) ? globalThis.Boolean(object.deleted) : false,
            createdAt: isSet(object.createdAt) ? globalThis.Number(object.createdAt) : 0,
            upvotes: isSet(object.upvotes) ? globalThis.Number(object.upvotes) : 0,
            downvotes: isSet(object.downvotes) ? globalThis.Number(object.downvotes) : 0,
            languageCode: isSet(object.languageCode) ? globalThis.String(object.languageCode) : "",
            lastModifiedAt: isSet(object.lastModifiedAt) ? globalThis.Number(object.lastModifiedAt) : 0,
            gilded: isSet(object.gilded) ? globalThis.Boolean(object.gilded) : false,
            score: isSet(object.score) ? globalThis.Number(object.score) : 0,
            permalink: isSet(object.permalink) ? globalThis.String(object.permalink) : "",
            hasMedia: isSet(object.hasMedia) ? globalThis.Boolean(object.hasMedia) : false,
            postId: isSet(object.postId) ? globalThis.String(object.postId) : "",
            subredditId: isSet(object.subredditId) ? globalThis.String(object.subredditId) : "",
            elementTypes: globalThis.Array.isArray(object?.elementTypes)
                ? object.elementTypes.map((e) => globalThis.String(e))
                : [],
            mediaUrls: globalThis.Array.isArray(object?.mediaUrls)
                ? object.mediaUrls.map((e) => globalThis.String(e))
                : [],
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.id !== "") {
            obj.id = message.id;
        }
        if (message.parentId !== "") {
            obj.parentId = message.parentId;
        }
        if (message.body !== "") {
            obj.body = message.body;
        }
        if (message.author !== "") {
            obj.author = message.author;
        }
        if (message.numReports !== 0) {
            obj.numReports = Math.round(message.numReports);
        }
        if (message.collapsedBecauseCrowdControl !== false) {
            obj.collapsedBecauseCrowdControl = message.collapsedBecauseCrowdControl;
        }
        if (message.spam !== false) {
            obj.spam = message.spam;
        }
        if (message.deleted !== false) {
            obj.deleted = message.deleted;
        }
        if (message.createdAt !== 0) {
            obj.createdAt = Math.round(message.createdAt);
        }
        if (message.upvotes !== 0) {
            obj.upvotes = Math.round(message.upvotes);
        }
        if (message.downvotes !== 0) {
            obj.downvotes = Math.round(message.downvotes);
        }
        if (message.languageCode !== "") {
            obj.languageCode = message.languageCode;
        }
        if (message.lastModifiedAt !== 0) {
            obj.lastModifiedAt = Math.round(message.lastModifiedAt);
        }
        if (message.gilded !== false) {
            obj.gilded = message.gilded;
        }
        if (message.score !== 0) {
            obj.score = Math.round(message.score);
        }
        if (message.permalink !== "") {
            obj.permalink = message.permalink;
        }
        if (message.hasMedia !== false) {
            obj.hasMedia = message.hasMedia;
        }
        if (message.postId !== "") {
            obj.postId = message.postId;
        }
        if (message.subredditId !== "") {
            obj.subredditId = message.subredditId;
        }
        if (message.elementTypes?.length) {
            obj.elementTypes = message.elementTypes;
        }
        if (message.mediaUrls?.length) {
            obj.mediaUrls = message.mediaUrls;
        }
        return obj;
    },
    create(base) {
        return CommentV2.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseCommentV2();
        message.id = object.id ?? "";
        message.parentId = object.parentId ?? "";
        message.body = object.body ?? "";
        message.author = object.author ?? "";
        message.numReports = object.numReports ?? 0;
        message.collapsedBecauseCrowdControl = object.collapsedBecauseCrowdControl ?? false;
        message.spam = object.spam ?? false;
        message.deleted = object.deleted ?? false;
        message.createdAt = object.createdAt ?? 0;
        message.upvotes = object.upvotes ?? 0;
        message.downvotes = object.downvotes ?? 0;
        message.languageCode = object.languageCode ?? "";
        message.lastModifiedAt = object.lastModifiedAt ?? 0;
        message.gilded = object.gilded ?? false;
        message.score = object.score ?? 0;
        message.permalink = object.permalink ?? "";
        message.hasMedia = object.hasMedia ?? false;
        message.postId = object.postId ?? "";
        message.subredditId = object.subredditId ?? "";
        message.elementTypes = object.elementTypes?.map((e) => e) || [];
        message.mediaUrls = object.mediaUrls?.map((e) => e) || [];
        return message;
    },
};
messageTypeRegistry.set(CommentV2.$type, CommentV2);
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;
}
