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.DealerPaymentAccountServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerPaymentAccountCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerPaymentAccountDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerPaymentAccountUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerPaymentAccountListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerPaymentAccountPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerPaymentAccountShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.DealerPaymentAccountVO;
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 = "DealerPaymentAccount", description = "经销商付款账户管理")
@RestController("operationDealerPaymentAccountController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class DealerPaymentAccountController {

	@DubboReference(version = "1.0.0")
	private final DealerPaymentAccountServiceI dealerPaymentAccountService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("listDealerPaymentAccount")
	@Operation(summary = "经销商付款账户列表", method = "GET")
	public MultiResponse<DealerPaymentAccountVO> listDealerPaymentAccount(@ModelAttribute @Validated DealerPaymentAccountListQry dealerPaymentAccountListQry) {
		return MultiResponse.of(dealerPaymentAccountService.list(dealerPaymentAccountListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_CREATE})
	@PostMapping("createDealerPaymentAccount")
	@Operation(summary = "创建经销商付款账户", method = "POST")
	public SingleResponse<DealerPaymentAccountVO> createDealerPaymentAccount(@RequestBody @Validated DealerPaymentAccountCreateCmd dealerPaymentAccountCreateCmd) {
		return SingleResponse.of(dealerPaymentAccountService.create(dealerPaymentAccountCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("showDealerPaymentAccount")
	@Operation(summary = "经销商付款账户详情", method = "GET")
	public SingleResponse<DealerPaymentAccountVO> showDealerPaymentAccount(@ModelAttribute @Validated DealerPaymentAccountShowQry dealerPaymentAccountShowQry) {
		return SingleResponse.of(dealerPaymentAccountService.show(dealerPaymentAccountShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_VIEW})
	@GetMapping("pageDealerPaymentAccount")
	@Operation(summary = "经销商付款账户列表", method = "GET")
	public PageResponse<DealerPaymentAccountVO> pageDealerPaymentAccount(@ModelAttribute @Validated DealerPaymentAccountPageQry dealerPaymentAccountPageQry) {
		PageDTO<DealerPaymentAccountVO> page = dealerPaymentAccountService.page(dealerPaymentAccountPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_UPDATE})
	@RequestMapping(value = "updateDealerPaymentAccount", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "经销商付款账户更新", method = "PATCH")
	public SingleResponse<DealerPaymentAccountVO> updateDealerPaymentAccount(@RequestBody @Validated DealerPaymentAccountUpdateCmd dealerPaymentAccountUpdateCmd) {
		return SingleResponse.of(dealerPaymentAccountService.update(dealerPaymentAccountUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_PAYMENT_ACCOUNT_DELETE})
	@DeleteMapping("destroyDealerPaymentAccount")
	@Operation(summary = "经销商付款账户删除", method = "DELETE")
	public Response destroyDealerPaymentAccount(@RequestBody @Validated DealerPaymentAccountDestroyCmd dealerPaymentAccountDestroyCmd) {
		dealerPaymentAccountService.destroy(dealerPaymentAccountDestroyCmd);
		return Response.buildSuccess();
	}
}
