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.BoxSpecServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxSpecCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxSpecDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.BoxSpecUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxSpecListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxSpecPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.BoxSpecShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.BoxSpecVO;
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 = "BoxSpec", description = "纸箱规格管理")
@RestController("operationBoxSpecController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class BoxSpecController {

	@DubboReference(version = "1.0.0")
    private final BoxSpecServiceI boxSpecService;

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_VIEW})
    @GetMapping("listBoxSpec")
    @Operation(summary = "纸箱规格列表", method = "GET")
    public MultiResponse<BoxSpecVO> listBoxSpec(@ModelAttribute @Validated BoxSpecListQry boxSpecListQry) {
        return MultiResponse.of(boxSpecService.list(boxSpecListQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_CREATE})
    @PostMapping("createBoxSpec")
    @Operation(summary = "创建纸箱规格", method = "POST")
    public SingleResponse<BoxSpecVO> createBoxSpec(@RequestBody @Validated BoxSpecCreateCmd boxSpecCreateCmd) {
        return SingleResponse.of(boxSpecService.create(boxSpecCreateCmd));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_VIEW})
    @GetMapping("showBoxSpec")
    @Operation(summary = "纸箱规格详情", method = "GET")
    public SingleResponse<BoxSpecVO> showBoxSpec(@ModelAttribute @Validated BoxSpecShowQry boxSpecShowQry) {
        return SingleResponse.of(boxSpecService.show(boxSpecShowQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_VIEW})
    @GetMapping("pageBoxSpec")
    @Operation(summary = "纸箱规格列表", method = "GET")
    public PageResponse<BoxSpecVO> pageBoxSpec(@ModelAttribute @Validated BoxSpecPageQry boxSpecPageQry) {
        PageDTO<BoxSpecVO> page = boxSpecService.page(boxSpecPageQry);
        return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_UPDATE})
    @RequestMapping(value = "updateBoxSpec", method = {RequestMethod.PATCH, RequestMethod.PUT})
    @Operation(summary = "纸箱规格更新", method = "PATCH")
    public SingleResponse<BoxSpecVO> updateBoxSpec(@RequestBody @Validated BoxSpecUpdateCmd boxSpecUpdateCmd) {
        return SingleResponse.of(boxSpecService.update(boxSpecUpdateCmd));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_BOX_SPEC_DELETE})
    @DeleteMapping("destroyBoxSpec")
    @Operation(summary = "纸箱规格删除", method = "DELETE")
    public Response destroyBoxSpec(@RequestBody @Validated BoxSpecDestroyCmd boxSpecDestroyCmd) {
        boxSpecService.destroy(boxSpecDestroyCmd);
        return Response.buildSuccess();
    }
}
