package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.AuditServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.AuditUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.AuditPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.AuditShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.AuditVO;
import com.xunhong.erp.turbo.base.dto.PageDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "Audit", description = "审核管理")
@RestController("operationAuditController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class AuditController {

	@DubboReference(version = "1.0.0")
	private final AuditServiceI auditService;

	@SaCheckLogin
	@GetMapping("showAudit")
	@Operation(summary = "审核详情", method = "GET")
	public SingleResponse<AuditVO> showAudit(@ModelAttribute @Validated AuditShowQry auditShowQry) {
		return SingleResponse.of(auditService.show(auditShowQry));
	}

	@SaCheckLogin
	@GetMapping("pageAudit")
	@Operation(summary = "审核列表", method = "GET")
	public PageResponse<AuditVO> pageAudit(@ModelAttribute @Validated AuditPageQry auditPageQry) {
		PageDTO<AuditVO> page = auditService.page(auditPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
	@RequestMapping(value = "updateAudit", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "审核更新", method = "PATCH")
	public SingleResponse<AuditVO> updateAudit(@RequestBody @Validated AuditUpdateCmd auditUpdateCmd) {
		return SingleResponse.of(auditService.update(auditUpdateCmd));
	}
}
