package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.bean.so.app.AppStrategySO;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.*;
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:25
 */
@RestController
@RequestMapping("appStrategy")
@Api(tags = "应用策略")
public class AppStrategyController {

    @PostMapping("callback")
    @ApiOperation("应用策略下发回调")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AppStrategySO.class)
    })
    public ResponseResult appStrategyCallback(@RequestParam @ApiParam(value = "回调内容", required = true) String data, @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_STRATEGY);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }
}
