package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.AppStoreInstallDTO;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.bean.vo.app.ClientAppStoreVO;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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("appStore")
@Api(tags = "应用商店")
public class AppStoreController {

    @PostMapping("list")
    @ApiOperation(value = "应用商店列表（0x3BC）", response = ClientAppStoreVO.class)
    public ResponseResult appStoreList(@ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.SHOW_ALL_APP);
        return strategy.cmdHandler(loginUserDTO.getId(), null);
    }

    @PostMapping("install/upload")
    @ApiOperation(value = "应用商店安装记录（0x3B9）", response = AppStoreInstallDTO.class)
    public ResponseResult appStoreVersionList(@RequestParam String data, @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_STORE_INSTALL);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }
}
