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

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.CompanyPaymentAccountServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyPaymentAccountCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyPaymentAccountDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CompanyPaymentAccountUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyPaymentAccountListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyPaymentAccountPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CompanyPaymentAccountShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.CompanyPaymentAccountVO;
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 = "CompanyPaymentAccount", description = "公司付款账户管理")
@RestController("operationCompanyPaymentAccountController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class CompanyPaymentAccountController {

	@DubboReference(version = "1.0.0")
	private final CompanyPaymentAccountServiceI companyPaymentAccountService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("listCompanyPaymentAccount")
	@Operation(summary = "公司付款账户列表", method = "GET")
	public MultiResponse<CompanyPaymentAccountVO> listCompanyPaymentAccount(@ModelAttribute @Validated CompanyPaymentAccountListQry companyPaymentAccountListQry) {
		return MultiResponse.of(companyPaymentAccountService.list(companyPaymentAccountListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_CREATE})
	@PostMapping("createCompanyPaymentAccount")
	@Operation(summary = "创建公司付款账户", method = "POST")
	public SingleResponse<CompanyPaymentAccountVO> createCompanyPaymentAccount(@RequestBody @Validated CompanyPaymentAccountCreateCmd companyPaymentAccountCreateCmd) {
		return SingleResponse.of(companyPaymentAccountService.create(companyPaymentAccountCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("showCompanyPaymentAccount")
	@Operation(summary = "公司付款账户详情", method = "GET")
	public SingleResponse<CompanyPaymentAccountVO> showCompanyPaymentAccount(@ModelAttribute @Validated CompanyPaymentAccountShowQry companyPaymentAccountShowQry) {
		return SingleResponse.of(companyPaymentAccountService.show(companyPaymentAccountShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("pageCompanyPaymentAccount")
	@Operation(summary = "公司付款账户列表", method = "GET")
	public PageResponse<CompanyPaymentAccountVO> pageCompanyPaymentAccount(@ModelAttribute @Validated CompanyPaymentAccountPageQry companyPaymentAccountPageQry) {
		PageDTO<CompanyPaymentAccountVO> page = companyPaymentAccountService.page(companyPaymentAccountPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_UPDATE})
	@RequestMapping(value = "updateCompanyPaymentAccount", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "公司付款账户更新", method = "PATCH")
	public SingleResponse<CompanyPaymentAccountVO> updateCompanyPaymentAccount(@RequestBody @Validated CompanyPaymentAccountUpdateCmd companyPaymentAccountUpdateCmd) {
		return SingleResponse.of(companyPaymentAccountService.update(companyPaymentAccountUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COMPANY_PAYMENT_ACCOUNT_DELETE})
	@DeleteMapping("destroyCompanyPaymentAccount")
	@Operation(summary = "公司付款账户删除", method = "DELETE")
	public Response destroyCompanyPaymentAccount(@RequestBody @Validated CompanyPaymentAccountDestroyCmd companyPaymentAccountDestroyCmd) {
		companyPaymentAccountService.destroy(companyPaymentAccountDestroyCmd);
		return Response.buildSuccess();
	}
}
