package ink.wgink.login.app.controller.app.api.appversion;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.FileException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.exceptions.UpdateException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.app.service.appversion.IAppVersionService;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResultData;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: AppVersionAppController
 * @Description: app版本
 * @Author: WangGeng
 * @Date: 2019/8/26 4:30 下午
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "app版本管理接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/appversion")
public class AppVersionAppController extends DefaultBaseController {

    @Autowired
    private IAppVersionService appVersionService;

    @ApiOperation(value = "获取app当前版本", notes = "获取app当前版本接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appVersionId", value = "app版本ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get-number/{appVersionId}")
    public SuccessResultData<Integer> getNumber(@PathVariable("appVersionId") String appVersionId) throws SearchException {
        return new SuccessResultData<>(appVersionService.getNumber(appVersionId));
    }

    @ApiOperation(value = "下载app", notes = "下载app接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appVersionId", value = "app版本ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("download/{appVersionId}")
    public void download(@PathVariable("appVersionId") String appVersionId, HttpServletRequest request, HttpServletResponse response) throws SearchException, FileException, UpdateException {
        appVersionService.download(appVersionId, request, response);
    }

}
