/**
 * #post_message.ts
 *
 * @packageDocumentation
 */
/* eslint-disable */
import _m0 from "protobufjs/minimal.js";
import { Struct, Value } from "../../../../../google/protobuf/struct.js";
import { messageTypeRegistry } from "../../../../../typeRegistry.js";
import { RealtimeSubscriptionsEffect } from "../../../effect_types/v1alpha/realtime_subscription.js";
export var WebViewInternalMessageScope;
(function (WebViewInternalMessageScope) {
    /** CLIENT - Message is intended for the client only */
    WebViewInternalMessageScope[WebViewInternalMessageScope["CLIENT"] = 0] = "CLIENT";
    WebViewInternalMessageScope[WebViewInternalMessageScope["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(WebViewInternalMessageScope || (WebViewInternalMessageScope = {}));
export function webViewInternalMessageScopeFromJSON(object) {
    switch (object) {
        case 0:
        case "CLIENT":
            return WebViewInternalMessageScope.CLIENT;
        case -1:
        case "UNRECOGNIZED":
        default:
            return WebViewInternalMessageScope.UNRECOGNIZED;
    }
}
export function webViewInternalMessageScopeToJSON(object) {
    switch (object) {
        case WebViewInternalMessageScope.CLIENT:
            return 0;
        case WebViewInternalMessageScope.UNRECOGNIZED:
        default:
            return -1;
    }
}
function createBaseWebViewInternalMessage() {
    return { type: "", scope: 0, analytics: undefined, effect: undefined, realtimeEffect: undefined, id: undefined };
}
export const WebViewInternalMessage = {
    $type: "devvit.ui.effects.web_view.v1alpha.WebViewInternalMessage",
    encode(message, writer = _m0.Writer.create()) {
        if (message.type !== "") {
            writer.uint32(10).string(message.type);
        }
        if (message.scope !== 0) {
            writer.uint32(16).int32(message.scope);
        }
        if (message.analytics !== undefined) {
            Struct.encode(Struct.wrap(message.analytics), writer.uint32(26).fork()).ldelim();
        }
        if (message.effect !== undefined) {
            Struct.encode(Struct.wrap(message.effect), writer.uint32(34).fork()).ldelim();
        }
        if (message.realtimeEffect !== undefined) {
            RealtimeSubscriptionsEffect.encode(message.realtimeEffect, writer.uint32(50).fork()).ldelim();
        }
        if (message.id !== undefined) {
            writer.uint32(42).string(message.id);
        }
        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 = createBaseWebViewInternalMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.type = reader.string();
                    continue;
                case 2:
                    if (tag !== 16) {
                        break;
                    }
                    message.scope = reader.int32();
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.analytics = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
                case 4:
                    if (tag !== 34) {
                        break;
                    }
                    message.effect = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
                case 6:
                    if (tag !== 50) {
                        break;
                    }
                    message.realtimeEffect = RealtimeSubscriptionsEffect.decode(reader, reader.uint32());
                    continue;
                case 5:
                    if (tag !== 42) {
                        break;
                    }
                    message.id = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            type: isSet(object.type) ? globalThis.String(object.type) : "",
            scope: isSet(object.scope) ? webViewInternalMessageScopeFromJSON(object.scope) : 0,
            analytics: isObject(object.analytics) ? object.analytics : undefined,
            effect: isObject(object.effect) ? object.effect : undefined,
            realtimeEffect: isSet(object.realtimeEffect)
                ? RealtimeSubscriptionsEffect.fromJSON(object.realtimeEffect)
                : undefined,
            id: isSet(object.id) ? globalThis.String(object.id) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.type !== "") {
            obj.type = message.type;
        }
        if (message.scope !== 0) {
            obj.scope = webViewInternalMessageScopeToJSON(message.scope);
        }
        if (message.analytics !== undefined) {
            obj.analytics = message.analytics;
        }
        if (message.effect !== undefined) {
            obj.effect = message.effect;
        }
        if (message.realtimeEffect !== undefined) {
            obj.realtimeEffect = RealtimeSubscriptionsEffect.toJSON(message.realtimeEffect);
        }
        if (message.id !== undefined) {
            obj.id = message.id;
        }
        return obj;
    },
    create(base) {
        return WebViewInternalMessage.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseWebViewInternalMessage();
        message.type = object.type ?? "";
        message.scope = object.scope ?? 0;
        message.analytics = object.analytics ?? undefined;
        message.effect = object.effect ?? undefined;
        message.realtimeEffect = (object.realtimeEffect !== undefined && object.realtimeEffect !== null)
            ? RealtimeSubscriptionsEffect.fromPartial(object.realtimeEffect)
            : undefined;
        message.id = object.id ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(WebViewInternalMessage.$type, WebViewInternalMessage);
function createBaseWebViewPostMessage() {
    return { type: "", data: undefined };
}
export const WebViewPostMessage = {
    $type: "devvit.ui.effects.web_view.v1alpha.WebViewPostMessage",
    encode(message, writer = _m0.Writer.create()) {
        if (message.type !== "") {
            writer.uint32(10).string(message.type);
        }
        if (message.data !== undefined) {
            Struct.encode(Struct.wrap(message.data), writer.uint32(18).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 = createBaseWebViewPostMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.type = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.data = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            type: isSet(object.type) ? globalThis.String(object.type) : "",
            data: isObject(object.data) ? object.data : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.type !== "") {
            obj.type = message.type;
        }
        if (message.data !== undefined) {
            obj.data = message.data;
        }
        return obj;
    },
    create(base) {
        return WebViewPostMessage.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseWebViewPostMessage();
        message.type = object.type ?? "";
        message.data = object.data ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(WebViewPostMessage.$type, WebViewPostMessage);
function createBaseWebViewAppMessage() {
    return { message: undefined, jsonString: undefined };
}
export const WebViewAppMessage = {
    $type: "devvit.ui.effects.web_view.v1alpha.WebViewAppMessage",
    encode(message, writer = _m0.Writer.create()) {
        if (message.message !== undefined) {
            Value.encode(Value.wrap(message.message), writer.uint32(10).fork()).ldelim();
        }
        if (message.jsonString !== undefined) {
            writer.uint32(18).string(message.jsonString);
        }
        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 = createBaseWebViewAppMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.message = Value.unwrap(Value.decode(reader, reader.uint32()));
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.jsonString = reader.string();
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            message: isSet(object?.message) ? object.message : undefined,
            jsonString: isSet(object.jsonString) ? globalThis.String(object.jsonString) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.message !== undefined) {
            obj.message = message.message;
        }
        if (message.jsonString !== undefined) {
            obj.jsonString = message.jsonString;
        }
        return obj;
    },
    create(base) {
        return WebViewAppMessage.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseWebViewAppMessage();
        message.message = object.message ?? undefined;
        message.jsonString = object.jsonString ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(WebViewAppMessage.$type, WebViewAppMessage);
function createBaseWebViewStateMessage() {
    return { state: undefined };
}
export const WebViewStateMessage = {
    $type: "devvit.ui.effects.web_view.v1alpha.WebViewStateMessage",
    encode(message, writer = _m0.Writer.create()) {
        if (message.state !== undefined) {
            Struct.encode(Struct.wrap(message.state), 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 = createBaseWebViewStateMessage();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.state = Struct.unwrap(Struct.decode(reader, reader.uint32()));
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return { state: isObject(object.state) ? object.state : undefined };
    },
    toJSON(message) {
        const obj = {};
        if (message.state !== undefined) {
            obj.state = message.state;
        }
        return obj;
    },
    create(base) {
        return WebViewStateMessage.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseWebViewStateMessage();
        message.state = object.state ?? undefined;
        return message;
    },
};
messageTypeRegistry.set(WebViewStateMessage.$type, WebViewStateMessage);
function createBaseWebViewPostMessageEffect() {
    return { webViewId: "", app: undefined, state: undefined };
}
export const WebViewPostMessageEffect = {
    $type: "devvit.ui.effects.web_view.v1alpha.WebViewPostMessageEffect",
    encode(message, writer = _m0.Writer.create()) {
        if (message.webViewId !== "") {
            writer.uint32(10).string(message.webViewId);
        }
        if (message.app !== undefined) {
            WebViewAppMessage.encode(message.app, writer.uint32(18).fork()).ldelim();
        }
        if (message.state !== undefined) {
            WebViewStateMessage.encode(message.state, 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 = createBaseWebViewPostMessageEffect();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    if (tag !== 10) {
                        break;
                    }
                    message.webViewId = reader.string();
                    continue;
                case 2:
                    if (tag !== 18) {
                        break;
                    }
                    message.app = WebViewAppMessage.decode(reader, reader.uint32());
                    continue;
                case 3:
                    if (tag !== 26) {
                        break;
                    }
                    message.state = WebViewStateMessage.decode(reader, reader.uint32());
                    continue;
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skipType(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            webViewId: isSet(object.webViewId) ? globalThis.String(object.webViewId) : "",
            app: isSet(object.app) ? WebViewAppMessage.fromJSON(object.app) : undefined,
            state: isSet(object.state) ? WebViewStateMessage.fromJSON(object.state) : undefined,
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.webViewId !== "") {
            obj.webViewId = message.webViewId;
        }
        if (message.app !== undefined) {
            obj.app = WebViewAppMessage.toJSON(message.app);
        }
        if (message.state !== undefined) {
            obj.state = WebViewStateMessage.toJSON(message.state);
        }
        return obj;
    },
    create(base) {
        return WebViewPostMessageEffect.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseWebViewPostMessageEffect();
        message.webViewId = object.webViewId ?? "";
        message.app = (object.app !== undefined && object.app !== null)
            ? WebViewAppMessage.fromPartial(object.app)
            : undefined;
        message.state = (object.state !== undefined && object.state !== null)
            ? WebViewStateMessage.fromPartial(object.state)
            : undefined;
        return message;
    },
};
messageTypeRegistry.set(WebViewPostMessageEffect.$type, WebViewPostMessageEffect);
function isObject(value) {
    return typeof value === "object" && value !== null;
}
function isSet(value) {
    return value !== null && value !== undefined;
}
