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.CostItemServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostItemCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostItemDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostItemDragCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.CostItemUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostItemListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostItemPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.CostItemShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.CostItemVO;
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 = "CostItem", description = "费用项目管理")
@RestController("operationCostItemController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class CostItemController {

	@DubboReference(version = "1.0.0")
	private final CostItemServiceI costItemService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_VIEW})
	@GetMapping("listCostItem")
	@Operation(summary = "费用项目列表", method = "GET")
	public MultiResponse<CostItemVO> listCostItem(@ModelAttribute @Validated CostItemListQry costItemListQry) {
		return MultiResponse.of(costItemService.list(costItemListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_CREATE})
	@PostMapping("createCostItem")
	@Operation(summary = "创建费用项目", method = "POST")
	public SingleResponse<CostItemVO> createCostItem(@RequestBody @Validated CostItemCreateCmd costItemCreateCmd) {
		return SingleResponse.of(costItemService.create(costItemCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_VIEW})
	@GetMapping("showCostItem")
	@Operation(summary = "费用项目详情", method = "GET")
	public SingleResponse<CostItemVO> showCostItem(@ModelAttribute @Validated CostItemShowQry costItemShowQry) {
		return SingleResponse.of(costItemService.show(costItemShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_VIEW})
	@GetMapping("pageCostItem")
	@Operation(summary = "费用项目列表", method = "GET")
	public PageResponse<CostItemVO> pageCostItem(@ModelAttribute @Validated CostItemPageQry costItemPageQry) {
		PageDTO<CostItemVO> page = costItemService.page(costItemPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_UPDATE})
	@RequestMapping(value = "updateCostItem", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "费用项目更新", method = "PATCH")
	public SingleResponse<CostItemVO> updateCostItem(@RequestBody @Validated CostItemUpdateCmd costItemUpdateCmd) {
		return SingleResponse.of(costItemService.update(costItemUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_DELETE})
	@DeleteMapping("destroyCostItem")
	@Operation(summary = "费用项目删除", method = "DELETE")
	public Response destroyCostItem(@RequestBody @Validated CostItemDestroyCmd costItemDestroyCmd) {
		costItemService.destroy(costItemDestroyCmd);
		return Response.buildSuccess();
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_COST_ITEM_UPDATE})
	@RequestMapping(value = "dragCostItem", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "费用项目拖拽排序", method = "PATCH")
	public Response dragCostItem(@RequestBody @Validated CostItemDragCmd costItemDragCmd) {
		costItemService.drag(costItemDragCmd);
		return Response.buildSuccess();
	}
}
