/**
 * 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>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.transport.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.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.transport.excel.TemporaryCreditLimitExcel;
import org.springblade.transport.pojo.entity.TemporaryCreditLimit;
import org.springblade.transport.pojo.vo.TemporaryCreditLimitVO;
import org.springblade.transport.service.ITemporaryCreditLimitService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 临时额度申请 控制器
 *
 * @author Chill
 */
@RestController
@AllArgsConstructor
@PreAuth(menu = "temporary_credit_limit")
@RequestMapping("/temporary-credit-limit")
@Tag(name = "临时额度申请", description = "临时额度申请")
public class TemporaryCreditLimitController extends BladeController {

	private final ITemporaryCreditLimitService temporaryCreditLimitService;

	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description = "传入id")
	public R<TemporaryCreditLimitVO> detail(@Parameter(description = "主键", required = true) @RequestParam Long id) {
		return R.data(temporaryCreditLimitService.detail(id));
	}

	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "分页", description = "传入temporaryCreditLimit")
	public R<IPage<TemporaryCreditLimitVO>> list(TemporaryCreditLimitVO temporaryCreditLimit, Query query) {
		return R.data(temporaryCreditLimitService.selectTemporaryCreditLimitPage(Condition.getPage(query), temporaryCreditLimit));
	}

	@PostMapping("/save-draft")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "保存草稿", description = "传入temporaryCreditLimit")
	public R saveDraft(@RequestBody TemporaryCreditLimit temporaryCreditLimit) {
		return R.status(temporaryCreditLimitService.saveDraft(temporaryCreditLimit));
	}

	@PostMapping("/submit")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增或修改", description = "传入temporaryCreditLimit")
	public R submit(@RequestBody TemporaryCreditLimit temporaryCreditLimit) {
		return R.status(temporaryCreditLimitService.submit(temporaryCreditLimit));
	}

	@PostMapping("/submit-approval")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "提交审批", description = "传入id")
	public R submitApproval(@Parameter(description = "主键", required = true) @RequestParam Long id) {
		return R.status(temporaryCreditLimitService.submitApproval(id));
	}

	@PostMapping("/approve")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "审批通过", description = "传入id")
	public R approve(@Parameter(description = "主键", required = true) @RequestParam Long id) {
		return R.status(temporaryCreditLimitService.approve(id));
	}

	@PostMapping("/reject")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "审批驳回", description = "传入id")
	public R reject(@Parameter(description = "主键", required = true) @RequestParam Long id) {
		return R.status(temporaryCreditLimitService.reject(id));
	}

	@PostMapping("/withdraw")
	@ApiOperationSupport(order = 8)
	@Operation(summary = "撤回审批", description = "传入id")
	public R withdraw(@Parameter(description = "主键", required = true) @RequestParam Long id) {
		return R.status(temporaryCreditLimitService.withdraw(id));
	}

	@PostMapping("/remove")
	@ApiOperationSupport(order = 9)
	@Operation(summary = "逻辑删除", description = "传入ids")
	public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
		return R.status(temporaryCreditLimitService.removeDraft(ids));
	}

	@GetMapping("/export-temporary-credit-limit")
	@ApiOperationSupport(order = 10)
	@Operation(summary = "导出临时额度申请")
	public void exportTemporaryCreditLimit(TemporaryCreditLimitVO temporaryCreditLimit, @RequestParam(required = false) String ids, HttpServletResponse response) {
		List<TemporaryCreditLimitExcel> list = temporaryCreditLimitService.exportTemporaryCreditLimit(temporaryCreditLimit, ids);
		ExcelUtil.export(response, "临时额度申请" + DateUtil.time(), "临时额度申请", list, TemporaryCreditLimitExcel.class);
	}

}
