package org.springblade.modules.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wn.common.datamodel.ResultDTO;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.modules.app.common.dto.AppVersionDTO;
import org.springblade.modules.app.common.query.AppVersionQuery;
import org.springblade.modules.app.common.query.LatestAppVersionQuery;
import org.springblade.modules.app.manager.AppVersionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@NonDS
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/version")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public class VersionController extends BladeController {
    @Autowired
    private AppVersionManager appVersionManger;

    @GetMapping("/page")
    //@ApiOperation(value = "分页查询app版本列表")
    public R<Page<AppVersionDTO>> pageAppVersion(AppVersionQuery appVersionQuery) {
        return R.data(appVersionManger.pageAppVersion(appVersionQuery));
    }

    @GetMapping("/{id}")
    //@ApiOperation(value = "获取app版本详情")
    public R getAppVersion(@PathVariable Long id) {
        return R.data(appVersionManger.getAppVersion(id));
    }

    @PostMapping
    //@ApiOperation(value = "新增app版本信息")
    public R addAppVersion(@RequestBody AppVersionDTO appVersionDTO) {
        return R.data(appVersionManger.addAppVersion(appVersionDTO));
    }

    @PutMapping
    //@ApiOperation(value = "修改app版本信息")
    public R updateAppVersion(@RequestBody AppVersionDTO appVersionDTO) {
        return R.data(appVersionManger.updateAppVersion(appVersionDTO));
    }

    @GetMapping("/latest")
    //@ApiOperation(value = "查询最新app版本信息")
    public R<AppVersionDTO> latestAppVersion(LatestAppVersionQuery latestAppVersionQuery) {
        return R.data(appVersionManger.latestVersion(latestAppVersionQuery));
    }
}
