package com.ywt.alipaympapi.controller;

import com.ywt.core.exception.AppMessageException;
import com.ywt.model.Code;
import com.ywt.model.PageVO;
import com.ywt.model.ResponseVO;
import com.ywt.request.register.CancelOrderRequest;
import com.ywt.request.register.OrderConfirmRequest;
import com.ywt.request.register.QueryOrderDetailRequest;
import com.ywt.request.register.QueryOrderListRequest;
import com.ywt.response.register.CancelOrderResponseData;
import com.ywt.response.register.OrderConfirmResponseData;
import com.ywt.response.register.QueryOrderDetailResponseData;
import com.ywt.response.register.QueryOrderListResponseData;
import com.ywt.alipaympapi.service.IsvRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Desc
 */
@RestController
@Slf4j
public class AppointmentController {

    @Autowired
    private IsvRegisterService isvRegisterService;

    /**
     * 挂号确认
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.orderConfirm")
    public ResponseVO<OrderConfirmResponseData> orderConfirm(OrderConfirmRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.orderConfirm(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("AppointmentController#orderConfirm(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 预约单列表
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.orderList")
    public ResponseVO<PageVO<QueryOrderListResponseData>> queryOrderList(QueryOrderListRequest request) {
        try {
            PageVO<QueryOrderListResponseData> data = isvRegisterService.queryOrderList(request);
            return ResponseVO.success(data);
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("AppointmentController#order.orderList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }


    }

    /**
     * 预约单详情
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.orderDetail")
    public ResponseVO<QueryOrderDetailResponseData> queryOrderDetail(QueryOrderDetailRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryOrderDetail(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("AppointmentController#queryOrderDetail(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 取消预约单
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.cancelOrder")
    public ResponseVO<CancelOrderResponseData> cancelOrder(CancelOrderRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.cancelOrder(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("AppointmentController#cancelOrder(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }
}
