package com.sikey.wa04.business.application.converter;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.sikey.wa04.business.domain.entity.message.Message;
import com.sikey.wa04.business.domain.entity.message.MessageId;
import com.sikey.wa04.common.dto.message.*;
import com.sikey.wa04.common.enums.MessageType;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.time.Instant;
import java.util.List;

@Slf4j
@UtilityClass
public class MessageConverter {
    private static final ObjectMapper objectMapper;

    static {
        objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // 空字段也可以序列化
        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);  // 空对象也可以序列化
    }


    /**
     * 转换成 mq 的消息
     *
     * @param message 消息
     * @return mq 消息
     */
    public Object toMessaging(Message message) {
        return switch (message.getType()) {
            case HEARTBEAT_MESSAGES, ACK_MESSAGES -> null;   // TODO not implemented
            case CHAT_TEXT_MESSAGE -> convertChatTextMessage(message);
            case CHAT_VIDEO_MESSAGE -> convertChatVideoMessage(message);
            case CHAT_VOICE_MESSAGE -> convertChatVoiceMessage(message);
            case CHAT_EMOJI_MESSAGE -> convertChatEmojiMessage(message);
            case CHAT_IMAGE_MESSAGE -> convertChatImageMessage(message);
            case DEVICE_BIND_STATE_CHANGE_MESSAGE -> convertBindStateChangeMessage(message);
            case LOCATION_POINT_CHANGE_MESSAGE -> convertLocationPointChangeNoticeMessage(message);
            case ADD_FRIEND_NOTICE_MESSAGE -> convertAddFriendNoticeMessage(message);
            case CONTACT_CHANGE_NOTICE_MESSAGE -> convertContactChangeNoticeMessage(message);
            case ALARM_CLOCK_CHANGE_NOTICE_MESSAGE -> convertAlarmClockChangeNoticeMessage(message);
            case SCHOOL_DISABLE_CHANGE_NOTICE_MESSAGE -> convertSchoolDisableChangeNoticeMessage(message);
            case WRISTWATCH_STARTUP_NOTICE_MESSAGE -> convertWristwatchStartupNoticeMessage(message);
            case WRISTWATCH_SHUTDOWN_NOTICE_MESSAGE -> convertWristwatchShutdownNoticeMessage(message);
            case REJECT_STRANGER_CHANGE_NOTICE_MESSAGE -> convertRejectStrangerChangeNoticeMessage(message);
            case MESSAGE_CENTER_CHANGE_NOTICE_MESSAGE -> convertMessageCenterChangeNoticeMessage(message);
            case VIDEO_CALL_IN_NOTICE_MESSAGE -> convertVideoCallInNoticeMessage(message);
            case VIDEO_CALL_OUT_NOTICE_MESSAGE -> convertVideoCallOutNoticeMessage(message);
            case ASK_LOCATION_POINT_NOTICE_MESSAGE -> convertAskLocationPointNoticeMessage(message);
            // 远程控制，发送消息通知设备端
            case REMOTE_CONTROL_REBOOT_NOTICE_MESSAGE -> convertRemoteControlRebootNoticeMessage(message);
            case REMOTE_CONTROL_SHUTDOWN_NOTICE_MESSAGE -> convertRemoteControlShutdownNoticeMessage(message);
            case REMOTE_CONTROL_RESTORE_FACTORY_SETTINGS_NOTICE_MESSAGE -> convertRemoteControlRestoreFactorySettingsNoticeMessage(message);
            // 移动云盘业务
            case NOTIFY_PARENTS_SUCCESSFUL_ACTIVATION ->
                    convertNotifyParentsSuccessfulActivationMessageMessage(message);
            case RELOGIN_ON_WWATCH -> convertReloginOnWwatchMessage(message);
            case ACTIVATE_CLOUD_PHOTO_ALBUM_SERVICE -> convertActivateCloudPhotoAlbumMessage(message);
            case NOTIFY_PARENTS_AUTHORIZATION -> convertNotifyParentsAuthorizationMessage(message);
            //APP设置应用管理中应用开关发送给手表的消息通知
            case REMOTE_APP_MANAGE_APP_SWITCH_NOTICE_MESSAGE -> convertAppManageAppSwitchNoticeMessage(message);
            //围栏告警消息通知
            case LOCATION_EXIT_SAFETY_FENCE_NOTICE_MESSAGE -> convertLocationExitSafetyFenceNoticeAppMessage(message);
            case LOCATION_ENTER_DANGER_FENCE_NOTICE_MESSAGE -> convertLocationEnterDangerFenceNoticeAppMessage(message);

            case DEVICE_LOW_BATTERY_NOTICE_MESSAGE -> null;
        };
    }

    private NotifyParentsSuccessfulActivationMessage convertNotifyParentsAuthorizationMessage(Message message) {
        NotifyParentsSuccessfulActivationMessage messaging = new NotifyParentsSuccessfulActivationMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), NotifyParentsSuccessfulActivationMessage.Content.class));
        return messaging;
    }

    private ActivateCloudPhotoAlbumMessage convertActivateCloudPhotoAlbumMessage(Message message) {
        ActivateCloudPhotoAlbumMessage messaging = new ActivateCloudPhotoAlbumMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ActivateCloudPhotoAlbumMessage.Content.class));
        return messaging;
    }

    private ReloginOnWwatchMessage convertReloginOnWwatchMessage(Message message) {
        ReloginOnWwatchMessage messaging = new ReloginOnWwatchMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ReloginOnWwatchMessage.Content.class));
        return messaging;
    }

    private NotifyParentsSuccessfulActivationMessage convertNotifyParentsSuccessfulActivationMessageMessage(Message message) {
        NotifyParentsSuccessfulActivationMessage messaging = new NotifyParentsSuccessfulActivationMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), NotifyParentsSuccessfulActivationMessage.Content.class));
        return messaging;
    }

    /*public Message formMessaging(AddFriendNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.ADD_FRIEND_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        AddFriendNoticeMessage.AddFriendNoticeContent.class));
    }*/

    /*public Message formMessaging(ContactChangeNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.CONTACT_CHANGE_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        ContactChangeNoticeMessage.ContactChangeNoticeContent.class));
    }*/

    public Message formMessaging(DeviceBindStateChangeNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.DEVICE_BIND_STATE_CHANGE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        DeviceBindStateChangeNoticeMessage.DeviceBindStateChangeNoticeContent.class));
    }

    public Message formMessaging(AskLocationPointNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.ASK_LOCATION_POINT_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        AskLocationPointNoticeMessage.AskLocationPointNoticeContent.class));
    }

    public Message formMessaging(RemoteControlShutdownNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.REMOTE_CONTROL_SHUTDOWN_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        RemoteControlShutdownNoticeMessage.RemoteControlShutdownNotice.class));
    }

    public Message formMessaging(RemoteControlRebootNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.REMOTE_CONTROL_REBOOT_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        RemoteControlRebootNoticeMessage.RemoteControlRebootNoticeContent.class));
    }

    public Message formMessaging(AlarmClockChangeNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.ALARM_CLOCK_CHANGE_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        AlarmClockChangeNoticeMessage.AlarmClockChangeNoticeMessageContent.class));
    }

    public Message formMessaging(AppManageAppSwitchNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.REMOTE_APP_MANAGE_APP_SWITCH_NOTICE_MESSAGE)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        AppManageAppSwitchNoticeMessage.AppManageAppSwitchNoticeContent.class));
    }

    public Message formMessaging(LocationExitSafetyFenceNoticeAppMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.LOCATION_EXIT_SAFETY_FENCE_NOTICE_MESSAGE)
                .setGroup(false)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        LocationExitSafetyFenceNoticeAppMessage.LocationExitSafetyFenceNoticeAppContent.class));
    }

    public Message formMessaging(LocationEnterDangerFenceNoticeAppMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.LOCATION_ENTER_DANGER_FENCE_NOTICE_MESSAGE)
                .setGroup(false)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        LocationEnterDangerFenceNoticeAppMessage.LocationEnterDangerFenceNoticeAppContent.class));
    }

    public Message formMessaging(RemoteControlRestoreFactorySettingsNoticeMessage noticeMessage) {
        return new Message()
                .setId(new MessageId(noticeMessage.getMsgId()))
                .setType(MessageType.REMOTE_CONTROL_RESTORE_FACTORY_SETTINGS_NOTICE_MESSAGE)
                .setGroup(false)
                .setSenderId(noticeMessage.getSendId())
                .setReceiverId(List.of(noticeMessage.getRecvId()))
                .setSendTime(Instant.ofEpochMilli(noticeMessage.getSendTime()))
                .setContent(objectMapper.convertValue(noticeMessage.getContent(),
                        RemoteControlRestoreFactorySettingsNoticeMessage.RemoteControlRestoreFactorySettingsNoticeContent.class));
    }

    private ChatTextMessage convertChatTextMessage(Message message) {
        ChatTextMessage messaging = new ChatTextMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());
        messaging.setIsGroup(message.isGroup());

        // 增加组
        messaging.setGroupId(message.getGroupId());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ChatTextMessage.ChatTextContent.class));
        return messaging;
    }

    private ChatVideoMessage convertChatVideoMessage(Message message) {
        ChatVideoMessage messaging = new ChatVideoMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());
        messaging.setIsGroup(message.isGroup());

        // 增加组
        messaging.setGroupId(message.getGroupId());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ChatTextMessage.ChatTextContent.class));
        return messaging;
    }

    private ChatVoiceMessage convertChatVoiceMessage(Message message) {
        ChatVoiceMessage messaging = new ChatVoiceMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());
        messaging.setIsGroup(message.isGroup());

        // 增加组
        messaging.setGroupId(message.getGroupId());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ChatTextMessage.ChatTextContent.class));
        return messaging;
    }

    private ChatEmojiMessage convertChatEmojiMessage(Message message) {
        ChatEmojiMessage messaging = new ChatEmojiMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());
        messaging.setIsGroup(message.isGroup());

        // 增加组
        messaging.setGroupId(message.getGroupId());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ChatTextMessage.ChatTextContent.class));
        return messaging;
    }

    private ChatImageMessage convertChatImageMessage(Message message) {
        ChatImageMessage messaging = new ChatImageMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());
        messaging.setIsGroup(message.isGroup());

        // 增加组
        messaging.setGroupId(message.getGroupId());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), ChatTextMessage.ChatTextContent.class));
        return messaging;
    }

    private DeviceBindStateChangeNoticeMessage convertBindStateChangeMessage(Message message) {
        DeviceBindStateChangeNoticeMessage messaging = new DeviceBindStateChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(),
                        DeviceBindStateChangeNoticeMessage.DeviceBindStateChangeNoticeContent.class));
        return messaging;
    }

    private LocationPointChangeNoticeMessage convertLocationPointChangeNoticeMessage(Message message) {
        LocationPointChangeNoticeMessage messaging = new LocationPointChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(),
                        LocationPointChangeNoticeMessage.LocationPointChangeNoticeMessageContent.class));
        return messaging;
    }


    private VideoCallInNoticeMessage convertVideoCallInNoticeMessage(Message message) {
        VideoCallInNoticeMessage messaging = new VideoCallInNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), VideoCallInNoticeMessage.VideoCallInNoticeContent.class));
        return messaging;
    }

    private VideoCallOutNoticeMessage convertVideoCallOutNoticeMessage(Message message) {
        VideoCallOutNoticeMessage messaging = new VideoCallOutNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), VideoCallOutNoticeMessage.VideoCallOutNoticeContent.class));
        return messaging;
    }

    private AskLocationPointNoticeMessage convertAskLocationPointNoticeMessage(Message message) {
        AskLocationPointNoticeMessage messaging = new AskLocationPointNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(), AskLocationPointNoticeMessage.AskLocationPointNoticeContent.class));
        return messaging;
    }

    private RemoteControlRebootNoticeMessage convertRemoteControlRebootNoticeMessage(Message message) {
        RemoteControlRebootNoticeMessage messaging = new RemoteControlRebootNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(),
                        RemoteControlRebootNoticeMessage.RemoteControlRebootNoticeContent.class));
        return messaging;
    }

    private RemoteControlShutdownNoticeMessage convertRemoteControlShutdownNoticeMessage(Message message) {
        RemoteControlShutdownNoticeMessage messaging = new RemoteControlShutdownNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(),
                        RemoteControlShutdownNoticeMessage.RemoteControlShutdownNotice.class));
        return messaging;
    }

    private RemoteControlRestoreFactorySettingsNoticeMessage convertRemoteControlRestoreFactorySettingsNoticeMessage(Message message) {
        RemoteControlRestoreFactorySettingsNoticeMessage messaging = new RemoteControlRestoreFactorySettingsNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(
                objectMapper.convertValue(message.getContent(),
                        RemoteControlRestoreFactorySettingsNoticeMessage.RemoteControlRestoreFactorySettingsNoticeContent.class));
        return messaging;
    }

    private AddFriendNoticeMessage convertAddFriendNoticeMessage(Message message) {
        AddFriendNoticeMessage messaging = new AddFriendNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                AddFriendNoticeMessage.AddFriendNoticeContent.class));
        return messaging;
    }

    private ContactChangeNoticeMessage convertContactChangeNoticeMessage(Message message) {
        ContactChangeNoticeMessage messaging = new ContactChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                ContactChangeNoticeMessage.ContactChangeNoticeContent.class));
        return messaging;
    }

    public AlarmClockChangeNoticeMessage convertAlarmClockChangeNoticeMessage(Message message) {
        AlarmClockChangeNoticeMessage messaging = new AlarmClockChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                AlarmClockChangeNoticeMessage.AlarmClockChangeNoticeMessageContent.class));
        return messaging;
    }

    public SchoolDisableChangeNoticeMessage convertSchoolDisableChangeNoticeMessage(Message message) {
        SchoolDisableChangeNoticeMessage messaging = new SchoolDisableChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                SchoolDisableChangeNoticeMessage.SchoolDisableChangeNoticeContent.class));
        return messaging;
    }

    public RejectStrangerChangeNoticeMessage convertRejectStrangerChangeNoticeMessage(Message message) {
        RejectStrangerChangeNoticeMessage messaging = new RejectStrangerChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                RejectStrangerChangeNoticeMessage.RejectStrangerChangeNoticeContent.class));
        return messaging;
    }

    public MessageCenterChangeNoticeMessage convertMessageCenterChangeNoticeMessage(Message message) {
        MessageCenterChangeNoticeMessage messaging = new MessageCenterChangeNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                MessageCenterChangeNoticeMessage.MessageCenterChangeNoticeMessageContent.class));
        return messaging;
    }

    public WristwatchStartupNoticeMessage convertWristwatchStartupNoticeMessage(Message message) {
        WristwatchStartupNoticeMessage messaging = new WristwatchStartupNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                WristwatchStartupNoticeMessage.WristwatchStartupNoticeContent.class));
        return messaging;
    }

    public WristwatchShutdownNoticeMessage convertWristwatchShutdownNoticeMessage(Message message) {
        WristwatchShutdownNoticeMessage messaging = new WristwatchShutdownNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                WristwatchShutdownNoticeMessage.WristwatchShutdownNotice.class));
        return messaging;
    }

    private AppManageAppSwitchNoticeMessage convertAppManageAppSwitchNoticeMessage(Message message) {
        AppManageAppSwitchNoticeMessage messaging = new AppManageAppSwitchNoticeMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setAckId(message.getAckId());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                AppManageAppSwitchNoticeMessage.AppManageAppSwitchNoticeContent.class));
        return messaging;
    }

    private LocationExitSafetyFenceNoticeAppMessage convertLocationExitSafetyFenceNoticeAppMessage(Message message) {
        LocationExitSafetyFenceNoticeAppMessage messaging = new LocationExitSafetyFenceNoticeAppMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                LocationExitSafetyFenceNoticeAppMessage.LocationExitSafetyFenceNoticeAppContent.class));
        return messaging;
    }

    private LocationEnterDangerFenceNoticeAppMessage convertLocationEnterDangerFenceNoticeAppMessage(Message message) {
        LocationEnterDangerFenceNoticeAppMessage messaging = new LocationEnterDangerFenceNoticeAppMessage();
        messaging.setMsgId(message.getId().getId())
                .setMsgType(message.getType())
                .setRecvId(message.getReceiverId().getFirst())
                .setSendId(message.getSenderId())
                .setSendTime(message.getSendTime().toEpochMilli());

        messaging.setContent(objectMapper.convertValue(message.getContent(),
                LocationEnterDangerFenceNoticeAppMessage.LocationEnterDangerFenceNoticeAppContent .class));
        return messaging;
    }

}
