package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.ClientUpgradeInfoDTO;
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:36
 */
@RestController
@RequestMapping("upgrade")
@Api(tags = "客户端升级")
public class ClientUpgradeController {

	@PostMapping("callback")
	@ApiOperation(value = "客户端升级下发回调(0x3B8)", response = ClientUpgradeInfoDTO.class)
	public ResponseResult uploadAppUse(@RequestParam @ApiParam(value = "回调内容", required = true) String data,
									   @ApiIgnore Authentication authentication) {
		LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
		CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_UPGRADE);
		return strategy.cmdHandler(loginUserDTO.getId(), data);
	}

}
