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.BoxProductServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxProductUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxProductShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.BoxProductVO;
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 = "BoxProduct", description = "纸箱产品管理")
@RestController("operationBoxProductController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class BoxProductController {

	@DubboReference(version = "1.0.0")
	private final BoxProductServiceI boxProductService;

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
	@GetMapping("listBoxProduct")
	@Operation(summary = "纸箱产品列表", method = "GET")
	public MultiResponse<BoxProductVO> listBoxProduct(@ModelAttribute @Validated BoxProductListQry boxProductListQry) {
		return MultiResponse.of(boxProductService.list(boxProductListQry));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_CREATE})
	@PostMapping("createBoxProduct")
	@Operation(summary = "创建纸箱产品", method = "POST")
	public SingleResponse<BoxProductVO> createBoxProduct(@RequestBody @Validated BoxProductCreateCmd boxProductCreateCmd) {
		return SingleResponse.of(boxProductService.create(boxProductCreateCmd));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
	@GetMapping("showBoxProduct")
	@Operation(summary = "纸箱产品详情", method = "GET")
	public SingleResponse<BoxProductVO> showBoxProduct(@ModelAttribute @Validated BoxProductShowQry boxProductShowQry) {
		return SingleResponse.of(boxProductService.show(boxProductShowQry));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_VIEW})
	@GetMapping("pageBoxProduct")
	@Operation(summary = "纸箱产品列表", method = "GET")
	public PageResponse<BoxProductVO> pageBoxProduct(@ModelAttribute @Validated BoxProductPageQry boxProductPageQry) {
		PageDTO<BoxProductVO> page = boxProductService.page(boxProductPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_UPDATE})
	@RequestMapping(value = "updateBoxProduct", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "纸箱产品更新", method = "PATCH")
	public SingleResponse<BoxProductVO> updateBoxProduct(@RequestBody @Validated BoxProductUpdateCmd boxProductUpdateCmd) {
		return SingleResponse.of(boxProductService.update(boxProductUpdateCmd));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_DELETE})
	@DeleteMapping("destroyBoxProduct")
	@Operation(summary = "纸箱产品删除", method = "DELETE")
	public Response destroyBoxProduct(@RequestBody @Validated BoxProductDestroyCmd boxProductDestroyCmd) {
		boxProductService.destroy(boxProductDestroyCmd);
		return Response.buildSuccess();
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_PRODUCT_UPDATE})
	@RequestMapping(value = "dragBoxProduct", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "纸箱产品拖拽排序", method = "PATCH")
	public Response dragBoxProduct(@RequestBody @Validated BoxProductDragCmd boxProductDragCmd) {
		boxProductService.drag(boxProductDragCmd);
		return Response.buildSuccess();
	}
}
