package org.dromara.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.system.domain.SysVersion;
import org.dromara.system.domain.bo.SysVersionBo;
import org.dromara.system.domain.vo.SysVersionVo;
import org.dromara.system.service.ISysVerisonService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fxh
 */
@Tag(name = "app版本管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/version")
public class SysVersionController {

    private final ISysVerisonService sysVerisonService;



    @Operation(summary = "查询app版本管理")
    @PostMapping("/list")
    public R<IPage<SysVersionVo>> list(@RequestBody SysVersionBo query, Page<SysVersion> page){
        return R.ok(sysVerisonService.getList(page,query));
    }

    @Operation(summary = "新增版本")
    @Log(title = "版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysVersion sysVersion) {
        if (!sysVerisonService.add(sysVersion)) {
            return R.fail("新增版本失败");
        }
        return R.ok("新增成功");
    }

    @Operation(summary = "修改状态")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @GetMapping("/update")
    public R updateStatus( @RequestParam Long id,
                      @RequestParam Integer status) {
        return R.ok(sysVerisonService.updateStatus(id,status));
    }

    @Operation(summary = "删除版本管理")
    @Log(title = "删除版本管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(sysVerisonService.removeById(id));
    }


}
