package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.StoreAppVersion;
import shop.alien.store.service.StoreAppVersionService;

/**
 * App版本表 前端控制器
 *
 * @author ssk
 * @since 2025-01-07
 */
@Slf4j
@Api(tags = {"二期-App版本"})
@ApiSort(13)
@CrossOrigin
@RestController
@RequestMapping("/version")
@RequiredArgsConstructor
public class StoreAppVersionController {

    private final StoreAppVersionService storeAppVersionService;

    @ApiOperation("获取最新版本号")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "appType", value = "app类型: 1:用户端, 2:商家端", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getLatestVersion")
    public R<StoreAppVersion> getAppealHistory(Integer appType) {
        return R.data(storeAppVersionService.getLatestVersion(appType));
    }

    @ApiOperation("保存或修改版本信息")
    @ApiOperationSupport(order = 2)
    @PostMapping("/saveVersionInfo")
    public R<String> saveVersionInfo(@RequestBody StoreAppVersion storeAppVersion) {
        return storeAppVersionService.saveVersionInfo(storeAppVersion);
    }

    @ApiOperation("列表分页查询")
    @ApiOperationSupport(order = 3)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appType", value = "app类型: 1:用户端, 2:商家端", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "条数", dataType = "Integer", paramType = "query", required = true, defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", paramType = "query", required = true, defaultValue = "1")
    })
    @GetMapping("/getList")
    public R<IPage<StoreAppVersion>> getList(Integer appType, Integer pageSize, Integer pageNum) {
        return R.data(storeAppVersionService.getList(appType, pageSize, pageNum));
    }
}
