package com.sckw.transport.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.transport.model.dto.AddressDropListDTO;
import com.sckw.transport.model.dto.WaybillOrderDTO;
import com.sckw.transport.service.WaybillManagementService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * @author lfdc
 * @description 运单管理controller
 * @date 2023-07-05 10:07:50
 */

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/kwtWaybillManagement")
public class WaybillManagementController {
    @Autowired
    WaybillManagementService waybillManagementService;

    @Valid
    @RequestMapping(name = "运单详情", value = "/waybillData", method = RequestMethod.GET)
    public HttpResult waybillData(@RequestParam("id") Long id) {
        try {
            return waybillManagementService.waybillData(id);
        } catch (Exception e) {
            log.error("托运订单详情:订单id {},error {} ", id, e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    @Valid
    @RequestMapping(name = "简洁版运单详情", value = "/waybillSimpleData", method = RequestMethod.GET)
    public HttpResult waybillSimpleData(@RequestParam("id") Long id) {
        try {
            return waybillManagementService.waybillSimpleData(id);
        } catch (Exception e) {
            log.error("托运订单详情:订单id {},error {} ", id, e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    @RequestMapping(name = "运单看板", value = "/waybillIndex", method = RequestMethod.POST)
    public HttpResult waybillIndex(@Validated @RequestBody WaybillOrderDTO waybillOrderDTO) {
        try {
            return waybillManagementService.waybillIndex(waybillOrderDTO);
        } catch (Exception e) {
            log.error("运单看板:订单id {},error {} ", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    @RequestMapping(name = "运单看板TOP", value = "/waybillIndexStatistics", method = RequestMethod.POST)
    public HttpResult waybillIndexStatistics(@Validated @RequestBody WaybillOrderDTO waybillOrderDTO) {
        try {
            return waybillManagementService.waybillIndexStatistics(waybillOrderDTO);
        } catch (Exception e) {
            log.error("运单看板TOP:订单id {},error {} ", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    /**
     * @desc 获取企业地址信息
     * @author zk
     * @date 2023/9/1
     **/
    @GetMapping("/findAddressList")
    public HttpResult findAddressList(){
        AddressDropListDTO addresss = waybillManagementService.findAddressList();
        return HttpResult.ok(addresss);
    }
}
