package com.sikey.wa04.api.message.client.wristwatch;

import com.sikey.wa04.business.application.service.message.HistoryMessageService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.HistoryMessageSessionRequest;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.ReadUnreadMessageRequest;
import com.sikey.wa04.business.infrastructure.dto.response.messaging.HistoryMessageSessionResponse;
import com.sikey.wa04.business.infrastructure.dto.response.messaging.HistoryUnreadMessageResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ProjectContextConstant.MESSAGE_URL + "/history/wristwatch")
public class HistoryMessageWristwatchController extends BaseController {

    @Resource
    private HistoryMessageService historyMessageService;

    /**
     * 加载会话消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @GetMapping("/session")
    public HistoryMessageSessionResponse session(@Valid HistoryMessageSessionRequest request) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return historyMessageService.loadWristwatchSession(request, genericManufacturerHeader);
    }

    /**
     * 手表端读取未读消息
     *
     * @param readUnreadMessageRequest 读取未读消息
     * @throws Exception
     */
    @Authenticated
    @PostMapping("/readUnreadMessage")
    public HistoryUnreadMessageResponse readUnreadMessage(@Valid @RequestBody ReadUnreadMessageRequest readUnreadMessageRequest) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return historyMessageService.wacthReadUnreadMessage(readUnreadMessageRequest,readUnreadMessageRequest.getIsOneClickRead() ,genericManufacturerHeader);
    }


}
