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.DealerRebateCustomerServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerRebateCustomerCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerRebateCustomerDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerRebateCustomerUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerRebateCustomerListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerRebateCustomerPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerRebateCustomerShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.DealerRebateCustomerVO;
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 = "DealerRebateCustomer", description = "经销商返点客户管理")
@RestController("operationDealerRebateCustomerController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class DealerRebateCustomerController {

	@DubboReference(version = "1.0.0")
	private final DealerRebateCustomerServiceI dealerRebateCustomerService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_VIEW})
	@GetMapping("listDealerRebateCustomer")
	@Operation(summary = "经销商返点客户列表", method = "GET")
	public MultiResponse<DealerRebateCustomerVO> listDealerRebateCustomer(@ModelAttribute @Validated DealerRebateCustomerListQry dealerRebateCustomerListQry) {
		return MultiResponse.of(dealerRebateCustomerService.list(dealerRebateCustomerListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_CREATE})
	@PostMapping("createDealerRebateCustomer")
	@Operation(summary = "创建经销商返点客户", method = "POST")
	public SingleResponse<DealerRebateCustomerVO> createDealerRebateCustomer(@RequestBody @Validated DealerRebateCustomerCreateCmd dealerRebateCustomerCreateCmd) {
		return SingleResponse.of(dealerRebateCustomerService.create(dealerRebateCustomerCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_VIEW})
	@GetMapping("showDealerRebateCustomer")
	@Operation(summary = "经销商返点客户详情", method = "GET")
	public SingleResponse<DealerRebateCustomerVO> showDealerRebateCustomer(@ModelAttribute @Validated DealerRebateCustomerShowQry dealerRebateCustomerShowQry) {
		return SingleResponse.of(dealerRebateCustomerService.show(dealerRebateCustomerShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_VIEW})
	@GetMapping("pageDealerRebateCustomer")
	@Operation(summary = "经销商返点客户列表", method = "GET")
	public PageResponse<DealerRebateCustomerVO> pageDealerRebateCustomer(@ModelAttribute @Validated DealerRebateCustomerPageQry dealerRebateCustomerPageQry) {
		PageDTO<DealerRebateCustomerVO> page = dealerRebateCustomerService.page(dealerRebateCustomerPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_UPDATE})
	@RequestMapping(value = "updateDealerRebateCustomer", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "经销商返点客户更新", method = "PATCH")
	public SingleResponse<DealerRebateCustomerVO> updateDealerRebateCustomer(@RequestBody @Validated DealerRebateCustomerUpdateCmd dealerRebateCustomerUpdateCmd) {
		return SingleResponse.of(dealerRebateCustomerService.update(dealerRebateCustomerUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_REBATE_CUSTOMER_DELETE})
	@DeleteMapping("destroyDealerRebateCustomer")
	@Operation(summary = "经销商返点客户删除", method = "DELETE")
	public Response destroyDealerRebateCustomer(@RequestBody @Validated DealerRebateCustomerDestroyCmd dealerRebateCustomerDestroyCmd) {
		dealerRebateCustomerService.destroy(dealerRebateCustomerDestroyCmd);
		return Response.buildSuccess();
	}
}
