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.DealerWarehouseServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerWarehouseCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerWarehouseDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.DealerWarehouseUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerWarehouseListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerWarehousePageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.DealerWarehouseShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.DealerWarehouseVO;
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 = "DealerWarehouse", description = "经销商仓库管理")
@RestController("operationDealerWarehouseController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class DealerWarehouseController {

	@DubboReference(version = "1.0.0")
	private final DealerWarehouseServiceI dealerWarehouseService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_VIEW})
	@GetMapping("listDealerWarehouse")
	@Operation(summary = "经销商仓库列表", method = "GET")
	public MultiResponse<DealerWarehouseVO> listDealerWarehouse(@ModelAttribute @Validated DealerWarehouseListQry dealerWarehouseListQry) {
		return MultiResponse.of(dealerWarehouseService.list(dealerWarehouseListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_CREATE})
	@PostMapping("createDealerWarehouse")
	@Operation(summary = "创建经销商仓库", method = "POST")
	public SingleResponse<DealerWarehouseVO> createDealerWarehouse(@RequestBody @Validated DealerWarehouseCreateCmd dealerWarehouseCreateCmd) {
		return SingleResponse.of(dealerWarehouseService.create(dealerWarehouseCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_VIEW})
	@GetMapping("showDealerWarehouse")
	@Operation(summary = "经销商仓库详情", method = "GET")
	public SingleResponse<DealerWarehouseVO> showDealerWarehouse(@ModelAttribute @Validated DealerWarehouseShowQry dealerWarehouseShowQry) {
		return SingleResponse.of(dealerWarehouseService.show(dealerWarehouseShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_VIEW})
	@GetMapping("pageDealerWarehouse")
	@Operation(summary = "经销商仓库列表", method = "GET")
	public PageResponse<DealerWarehouseVO> pageDealerWarehouse(@ModelAttribute @Validated DealerWarehousePageQry dealerWarehousePageQry) {
		PageDTO<DealerWarehouseVO> page = dealerWarehouseService.page(dealerWarehousePageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_UPDATE})
	@RequestMapping(value = "updateDealerWarehouse", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "经销商仓库更新", method = "PATCH")
	public SingleResponse<DealerWarehouseVO> updateDealerWarehouse(@RequestBody @Validated DealerWarehouseUpdateCmd dealerWarehouseUpdateCmd) {
		return SingleResponse.of(dealerWarehouseService.update(dealerWarehouseUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_DEALER_WAREHOUSE_DELETE})
	@DeleteMapping("destroyDealerWarehouse")
	@Operation(summary = "经销商仓库删除", method = "DELETE")
	public Response destroyDealerWarehouse(@RequestBody @Validated DealerWarehouseDestroyCmd dealerWarehouseDestroyCmd) {
		dealerWarehouseService.destroy(dealerWarehouseDestroyCmd);
		return Response.buildSuccess();
	}
}
