package com.clx.performance.controller.feign;

import com.clx.performance.param.feign.CancelOrderGoodsParam;
import com.clx.performance.param.feign.DistributionTruckParam;
import com.clx.performance.param.pc.OrderChildReportParam;
import com.clx.performance.service.OrderGoodsService;
import com.clx.performance.vo.feign.FreightEstimateVO;
import com.clx.performance.vo.feign.OrderGoodsFeignVO;
import com.msl.common.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/feign/orderGoods")
@Validated
@Tag(name = "货单Feign")
@AllArgsConstructor
public class OrderGoodsFeignController {

    private final OrderGoodsService orderGoodsService;

    @GetMapping({"/getOrderGoodsListByOrderNo"})
    List<OrderGoodsFeignVO> getOrderGoodsListByOrderNo(@RequestParam("userNo") @NotNull(message = "订单编号不可为空") String orderNo) {
        return orderGoodsService.getOrderGoodsListByOrderNo(orderNo);
    }

    @GetMapping({"/updateOrderGoodsStopFlag"})
    Result<Boolean> updateOrderGoodsStopFlag(@RequestParam("orderNo") @NotBlank(message = "订单编号不可为空") String orderNo,
                                             @RequestParam("stopFlag") @NotNull(message = "暂停标志不可为空") Integer stopFlag) {
        return Result.ok(orderGoodsService.updateOrderGoodsStopFlag(orderNo,stopFlag));
    }

    @GetMapping({"/updateSystemAddressId"})
    Result<Boolean> updateSystemAddressId(@RequestParam("ownerAddressId") @NotNull(message = "货主地址id不能为空") Integer ownerAddressId,
                                             @RequestParam("systemAddressId") @NotNull(message = "系统地址id不能为空") Integer systemAddressId) {
        return Result.ok(orderGoodsService.updateSystemAddressId(ownerAddressId,systemAddressId));
    }


    @PostMapping({"/listFreightEstimate"})
    Result<FreightEstimateVO> listFreightEstimate(@RequestBody OrderChildReportParam param) {
        return Result.ok(orderGoodsService.listFreightEstimate(param));
    }

    @Operation(summary = "定向单绑定车辆", description = "<br>By:刘海泉")
    @PostMapping({"/saveBindTruck"})
    Result<Object> saveBindTruck(@RequestBody @Validated DistributionTruckParam param) {
        orderGoodsService.saveBindTruck(param);
        return Result.ok();
    }

    @Operation(summary = "取消货单", description = "<br>By:李瑞新")
    @PostMapping({"/cancelOrderGoods"})
    Result<BigDecimal> cancelOrderGoods(@RequestBody @Validated CancelOrderGoodsParam param) {
        return Result.ok(orderGoodsService.cancelOrderGoods(param));
    }


    @Operation(summary = "更新挂单运费", description = "<br>By:艾庆国")
    @PostMapping(value = {"/updatePendingOrderFright"})
    Result<Void> updatePendingOrderFright(@RequestParam("orderGoodsNo") String orderGoodsNo,
                                          @RequestParam("pendingOrderFreight") BigDecimal pendingOrderFreight){

        orderGoodsService.updateFrightPrice(orderGoodsNo, pendingOrderFreight);
        return Result.ok();
    }

}
