/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.pojo.entity.AppVersion;
import org.springblade.system.service.AppVersionService;
import org.springframework.web.bind.annotation.*;


@RestController
@AllArgsConstructor
@RequestMapping("appVersion")
@Tag(name = "APP版本管理", description = "APP版本管理")
public class AppVersionController extends BladeController {
	private static final Logger logger = LoggerFactory.getLogger(AppVersionController.class);

	private final AppVersionService appVersionService;

	/**
	 * 分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "分页")
	public R<IPage<AppVersion>> page(AppVersion modelVo, Query query) {
		try {
			return R.data(appVersionService.page(modelVo,query));
		} catch (Exception e) {
			logger.error("appVersion/page：" + e.getMessage());
			return R.fail(e.getMessage());
		}
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail/{id}")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "详情")
	public R<AppVersion> detail(@PathVariable Long id) {
		try {
			return R.data(appVersionService.detail(id));
		} catch (Exception e) {
			logger.error("appVersion/detail：" + e.getMessage());
			return R.fail(e.getMessage());
		}
	}

	/**
	 * 发布版本/编辑
	 */
	@PostMapping("/publishOrEdit")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "发布版本/编辑")
	public R<AppVersion> publishOrEdit(@Valid @RequestBody AppVersion modelVo) {
		try {
			return R.data(appVersionService.publishOrEdit(modelVo));
		} catch (Exception e) {
			logger.error("appVersion/publishOrEdit：" + e.getMessage());
			return R.fail(e.getMessage());
		}
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "删除")
	public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
		try {
			return R.status(appVersionService.removeByIds(Func.toLongList(ids)));
		} catch (Exception e) {
			logger.error("appVersion/remove：" + e.getMessage());
			return R.fail(e.getMessage());
		}
	}

}
