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.CostServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.CostVO;
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 = "Cost", description = "费用管理")
@RestController("operationCostController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class CostController {

	@DubboReference(version = "1.0.0")
    private final CostServiceI costService;

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_VIEW})
    @GetMapping("listCost")
    @Operation(summary = "费用列表", method = "GET")
    public MultiResponse<CostVO> listCost(@ModelAttribute @Validated CostListQry costListQry) {
        return MultiResponse.of(costService.list(costListQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_CREATE})
    @PostMapping("createCost")
    @Operation(summary = "创建费用", method = "POST")
    public SingleResponse<CostVO> createCost(@RequestBody @Validated CostCreateCmd costCreateCmd) {
        return SingleResponse.of(costService.create(costCreateCmd));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_VIEW})
    @GetMapping("showCost")
    @Operation(summary = "费用详情", method = "GET")
    public SingleResponse<CostVO> showCost(@ModelAttribute @Validated CostShowQry costShowQry) {
        return SingleResponse.of(costService.show(costShowQry));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_VIEW})
    @GetMapping("pageCost")
    @Operation(summary = "费用列表", method = "GET")
    public PageResponse<CostVO> pageCost(@ModelAttribute @Validated CostPageQry costPageQry) {
        PageDTO<CostVO> page = costService.page(costPageQry);
        return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_UPDATE})
    @RequestMapping(value = "updateCost", method = {RequestMethod.PATCH, RequestMethod.PUT})
    @Operation(summary = "费用更新", method = "PATCH")
    public SingleResponse<CostVO> updateCost(@RequestBody @Validated CostUpdateCmd costUpdateCmd) {
        return SingleResponse.of(costService.update(costUpdateCmd));
    }

    @SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_DELETE})
    @DeleteMapping("destroyCost")
    @Operation(summary = "费用删除", method = "DELETE")
    public Response destroyCost(@RequestBody @Validated CostDestroyCmd costDestroyCmd) {
        costService.destroy(costDestroyCmd);
        return Response.buildSuccess();
    }


	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_UPDATE})
	@RequestMapping(value = "dragCost", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "费用拖拽排序", method = "PATCH")
	public Response dragCost(@RequestBody @Validated CostDragCmd costDragCmd) {
		costService.drag(costDragCmd);
		return Response.buildSuccess();
	}
}
