package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.AppPushCallBackInfoDTO;
import com.skr.mdm.dto.AppPushPauseCallBackDTO;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author nfq
 * @date 2020/8/11 16:09
 */
@RestController
@RequestMapping("appPush")
@Api(tags = "应用推送")
public class AppPushController {

    @PostMapping("callback")
    @ApiOperation(value = "应用推送下发回调(0x38B)", response = AppPushCallBackInfoDTO.class)
    public ResponseResult appPushCallback(@RequestParam @ApiParam(value = "回调内容", required = true) String data,
                                           @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_PUSH_CB);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }

    @PostMapping("pause/callback")
    @ApiOperation(value = "应用推送暂停回调(0x38A)", response = AppPushPauseCallBackDTO.class)
    public ResponseResult appPushPauseCallback(@RequestParam @ApiParam(value = "回调内容", required = true) String data,
                                           @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_PUSH_PAUSE_CB);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }

}
