package org.springblade.application.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.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.application.pojo.entity.ApplicationInfoEntity;
import org.springblade.application.service.IApplicationService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 应用管理 控制器
 *
 * @author wth
 * @since 2024-07-04
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/application")
@Tag(name = "应用管理接口", description = "应用管理接口")
public class ApplicationController extends BladeController {

	private final IApplicationService applicationService;

	/**
	 * 应用列表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "列表", description = "")
	public R page(@RequestParam Map<String, Object> params, Query query) {
		IPage<ApplicationInfoEntity> pages = applicationService.getPage(Condition.getPage(query), params);
		return R.data(pages);
	}

	/**
	 * 应用详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "详情", description = "传入id")
	public R detail(ApplicationInfoEntity applicationInfoEntity) {
		ApplicationInfoEntity detail = applicationService.getOne(Condition.getQueryWrapper(applicationInfoEntity));
		return R.data(detail);
	}

	/**
	 * 应用上传
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "应用上传", description = "传入applicationInfoEntity")
	public R save(@RequestBody ApplicationInfoEntity applicationInfoEntity) {
		return R.status(applicationService.save(applicationInfoEntity));
	}

	/**
	 * 应用修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "应用修改", description = "传入applicationInfoEntity")
	public R update(@RequestBody ApplicationInfoEntity applicationInfoEntity) {
		return R.status(applicationService.updateById(applicationInfoEntity));
	}

	/**
	 * 应用删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "逻辑删除", description = "传入ids")
	public R remove(@RequestParam String ids) {
		return R.status(applicationService.deleteLogic(Func.toLongList(ids)));
	}
}
