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.BoxBrandServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxBrandUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxBrandShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.BoxBrandVO;
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 = "BoxBrand", description = "纸箱品牌管理")
@RestController("operationBoxBrandController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class BoxBrandController {

	@DubboReference(version = "1.0.0")
	private final BoxBrandServiceI boxBrandService;

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
	@GetMapping("listBoxBrand")
	@Operation(summary = "纸箱品牌列表", method = "GET")
	public MultiResponse<BoxBrandVO> listBoxBrand(@ModelAttribute @Validated BoxBrandListQry boxBrandListQry) {
		return MultiResponse.of(boxBrandService.list(boxBrandListQry));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_CREATE})
	@PostMapping("createBoxBrand")
	@Operation(summary = "创建纸箱品牌", method = "POST")
	public SingleResponse<BoxBrandVO> createBoxBrand(@RequestBody @Validated BoxBrandCreateCmd boxBrandCreateCmd) {
		return SingleResponse.of(boxBrandService.create(boxBrandCreateCmd));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
	@GetMapping("showBoxBrand")
	@Operation(summary = "纸箱品牌详情", method = "GET")
	public SingleResponse<BoxBrandVO> showBoxBrand(@ModelAttribute @Validated BoxBrandShowQry boxBrandShowQry) {
		return SingleResponse.of(boxBrandService.show(boxBrandShowQry));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_VIEW})
	@GetMapping("pageBoxBrand")
	@Operation(summary = "纸箱品牌列表", method = "GET")
	public PageResponse<BoxBrandVO> pageBoxBrand(@ModelAttribute @Validated BoxBrandPageQry boxBrandPageQry) {
		PageDTO<BoxBrandVO> page = boxBrandService.page(boxBrandPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_UPDATE})
	@RequestMapping(value = "updateBoxBrand", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "纸箱品牌更新", method = "PATCH")
	public SingleResponse<BoxBrandVO> updateBoxBrand(@RequestBody @Validated BoxBrandUpdateCmd boxBrandUpdateCmd) {
		return SingleResponse.of(boxBrandService.update(boxBrandUpdateCmd));
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_DELETE})
	@DeleteMapping("destroyBoxBrand")
	@Operation(summary = "纸箱品牌删除", method = "DELETE")
	public Response destroyBoxBrand(@RequestBody @Validated BoxBrandDestroyCmd boxBrandDestroyCmd) {
		boxBrandService.destroy(boxBrandDestroyCmd);
		return Response.buildSuccess();
	}

	@SaCheckLogin
//	@SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_BRAND_UPDATE})
	@RequestMapping(value = "dragBoxBrand", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "纸箱品牌拖拽排序", method = "PATCH")
	public Response dragBoxBrand(@RequestBody @Validated BoxBrandDragCmd boxBrandDragCmd) {
		boxBrandService.drag(boxBrandDragCmd);
		return Response.buildSuccess();
	}
}
