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.ShipOrderServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ShipOrderCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ShipOrderDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ShipOrderGenerateDocumentCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ShipOrderUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.ShipOrderListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.ShipOrderPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.ShipOrderShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.ShipOrderVO;
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 = "ShipOrder", description = "发货单管理")
@RestController("operationShipOrderController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class ShipOrderController {

	@DubboReference(version = "1.0.0")
	private final ShipOrderServiceI shipOrderService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_VIEW})
	@GetMapping("listShipOrder")
	@Operation(summary = "发货单列表", method = "GET")
	public MultiResponse<ShipOrderVO> listShipOrder(@ModelAttribute @Validated ShipOrderListQry shipOrderListQry) {
		return MultiResponse.of(shipOrderService.list(shipOrderListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_CREATE})
	@PostMapping("createShipOrder")
	@Operation(summary = "创建发货单", method = "POST")
	public SingleResponse<ShipOrderVO> createShipOrder(@RequestBody @Validated ShipOrderCreateCmd shipOrderCreateCmd) {
		return SingleResponse.of(shipOrderService.create(shipOrderCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_VIEW})
	@GetMapping("showShipOrder")
	@Operation(summary = "发货单详情", method = "GET")
	public SingleResponse<ShipOrderVO> showShipOrder(@ModelAttribute @Validated ShipOrderShowQry shipOrderShowQry) {
		return SingleResponse.of(shipOrderService.show(shipOrderShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_VIEW})
	@GetMapping("pageShipOrder")
	@Operation(summary = "发货单列表", method = "GET")
	public PageResponse<ShipOrderVO> pageShipOrder(@ModelAttribute @Validated ShipOrderPageQry shipOrderPageQry) {
		PageDTO<ShipOrderVO> page = shipOrderService.page(shipOrderPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_UPDATE})
	@RequestMapping(value = "updateShipOrder", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "发货单更新", method = "PATCH")
	public SingleResponse<ShipOrderVO> updateShipOrder(@RequestBody @Validated ShipOrderUpdateCmd shipOrderUpdateCmd) {
		return SingleResponse.of(shipOrderService.update(shipOrderUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_UPDATE})
	@RequestMapping(value = "generateDocumentShipOrder", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "发货单生成单据", method = "PATCH")
	public Response generateDocumentShipOrder(@RequestBody @Validated ShipOrderGenerateDocumentCmd shipOrderGenerateDocumentCmd) {
		shipOrderService.generateDocument(shipOrderGenerateDocumentCmd);
		return Response.buildSuccess();
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_SHIP_ORDER_DELETE})
	@DeleteMapping("destroyShipOrder")
	@Operation(summary = "发货单删除", method = "DELETE")
	public Response destroyShipOrder(@RequestBody @Validated ShipOrderDestroyCmd shipOrderDestroyCmd) {
		shipOrderService.destroy(shipOrderDestroyCmd);
		return Response.buildSuccess();
	}
}
