package com.njcn.system.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.system.pojo.param.AppVersionParam;
import com.njcn.system.pojo.po.AppVersion;
import com.njcn.system.pojo.vo.AppVersionVo;
import com.njcn.system.service.IAppVersionService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xy
 * @since 2024-11-21
 */
@RestController
@Slf4j
@RequestMapping("/appVersion")
@Api(tags = "版本信息")
@AllArgsConstructor
public class VersionController extends BaseController {

    private final IAppVersionService appVersionService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("新增版本信息")
    @ApiImplicitParam(name = "param", value = "app版本信息", required = true)
    public HttpResult<String> add(@RequestBody @Validated AppVersionParam param){
        String methodDescribe = getMethodDescribe("add");
        boolean result = appVersionService.add(param);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "新增成功", methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "新增失败", methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLastData")
    @ApiOperation("查询最新版本信息")
    @ApiImplicitParam(name = "versionType", value = "版本类型(APP WEB)", required = true)
    public HttpResult<AppVersionVo> getLastData(@RequestParam("versionType") String versionType){
        String methodDescribe = getMethodDescribe("getLastData");
        AppVersionVo vo = appVersionService.getLastData(versionType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAllData")
    @ApiOperation("查询所有版本信息")
    @ApiImplicitParam(name = "versionType", value = "版本类型(APP WEB)")
    public HttpResult< List<AppVersion>> getAllData(@RequestParam(value = "versionType",required = false) String versionType){
        String methodDescribe = getMethodDescribe("getAllData");
        List<AppVersion> list = appVersionService.getAllData(versionType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}

