package com.sckw.order.controller;

import com.sckw.core.web.response.HttpResult;
import com.sckw.order.model.vo.req.*;
import com.sckw.order.serivce.KwoTradeOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 贸易订单相关
 * @author: yzc
 * @date: 2023-07-07 14:10
 */
@RestController
@RequestMapping(value = "/kwoTradeOrder")
@RequiredArgsConstructor
public class KwoTradeOrderController {

    private final KwoTradeOrderService kwoTradeOrderService;

    /**
     * @desc: 采购下单草稿
     * @author: yzc
     * @date: 2023-07-07 15:29
     * @Param purchaseOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/addPurchaseOrderDraft", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addPurchaseOrderDraft(@RequestBody @Validated PurchaseOrderDraftParam param) {
        kwoTradeOrderService.addPurchaseOrderDraft(param);
        return HttpResult.ok("采购下单草稿保存成功");
    }

    /**
     * @desc: 采购下单提交
     * @author: yzc
     * @date: 2023-07-07 15:29
     * @Param purchaseOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/addPurchaseOrderSubmit", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addPurchaseOrderSubmit(@RequestBody @Validated PurchaseOrderParam purchaseOrderParam) {
        kwoTradeOrderService.addPurchaseOrderSubmit(purchaseOrderParam);
        return HttpResult.ok("采购下单提交成功");
    }

    /**
     * @desc: 代客下单草稿
     * @author: yzc
     * @date: 2023-07-07 15:29
     * @Param valetOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/addValetOrderDraft", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addValetOrderDraft(@RequestBody @Validated ValetOrderDraftParam param) {
        kwoTradeOrderService.addValetOrderDraft(param);
        return HttpResult.ok("代客下单草稿保存成功");
    }


    /**
     * @desc: 代客下单提交
     * @author: yzc
     * @date: 2023-07-07 15:30
     * @Param valetOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/addValetOrderSubmit", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult addValetOrderSubmit(@RequestBody @Validated ValetOrderParam valetOrderParam) {
        kwoTradeOrderService.addValetOrderSubmit(valetOrderParam);
        return HttpResult.ok("代客下单提交成功");
    }

    /**
     * @desc: 订单详情
     * @author: yzc
     * @date: 2023-07-07 15:30
     * @Param id:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok("贸易订单详情查询成功", kwoTradeOrderService.getDetail(id));
    }

    /**
     * @desc: 修改订单
     * @author: yzc
     * @date: 2023-07-07 15:34
     * @Param updateOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult update(@RequestBody @Validated UpdateOrderParam updateOrderParam) {
        kwoTradeOrderService.update(updateOrderParam);
        return HttpResult.ok("订单修改成功");
    }

    /**
     * @desc: 订单受理
     * @author: yzc
     * @date: 2023-07-12 11:16
     * @Param acceptanceOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/acceptanceOrder", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult acceptanceOrder(@RequestBody @Validated AcceptanceOrderParam acceptanceOrderParam) {
        kwoTradeOrderService.acceptanceOrder(acceptanceOrderParam);
        return HttpResult.ok("订单受理成功");
    }

    /**
     * @desc: 驳回订单
     * @author: yzc
     * @date: 2023-07-12 11:22
     * @Param rejectOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/rejectOrder", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult rejectOrder(@RequestBody @Validated RejectOrderParam rejectOrderParam) {
        kwoTradeOrderService.rejectOrder(rejectOrderParam);
        return HttpResult.ok("订单驳回成功");
    }

    /**
     * @desc: 驳回订单原因查询
     * @author: yzc
     * @date: 2023-07-12 11:22
     * @Param id:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/rejectReason")
    public HttpResult rejectReason(@RequestParam Long id) {
        return HttpResult.ok("驳回订单原因查询成功", kwoTradeOrderService.rejectReason(id));
    }

    /**
     * @desc: 完结订单
     * @author: yzc
     * @date: 2023-07-12 17:29
     * @Param completeOrderParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/completeOrder", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult completeOrder(@RequestBody @Validated CompleteOrderParam completeOrderParam) {
        kwoTradeOrderService.completeOrder(completeOrderParam);
        return HttpResult.ok("订单完结成功");
    }


    /**
     * @desc: 批量删除
     * @author: yzc
     * @date: 2023-07-12 17:34
     * @Param param:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GlobalTransactional(name = "default_tx_group")
    @PostMapping(value = "/batchDelete", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult batchDelete(@RequestBody @Validated BatchDeleteParam param) {
        kwoTradeOrderService.batchDelete(param);
        return HttpResult.ok("订单批量删除成功");
    }

    /**
     * @desc: 获取贸易订单地址下拉列表
     * @author: yzc
     * @date: 2023-08-02 17:26
     * @Param param:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/getAddressDropList")
    public HttpResult getAddressDropList() {
        return HttpResult.ok("获取贸易订单地址下拉列表成功", kwoTradeOrderService.getAddressDropList());
    }

}
