package com.ywt.alipaympapi.controller;

import com.ywt.alipaympapi.service.IsvRegisterService;
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.queue.QueryQueueListRequest;
import com.ywt.request.register.*;
import com.ywt.response.queue.QueryQueueListResponse;
import com.ywt.response.register.*;
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;

import java.util.List;

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

    @Autowired
    private IsvRegisterService isvRegisterService;

    /**
     * 科室列表查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.departmentList")
    public ResponseVO<List<QueryDepartmentListResponseData>> queryDepartmentList(QueryDepartmentListRequest request) throws Exception {
        try {
            return ResponseVO.success(isvRegisterService.queryDepartmentList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDepartmentList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 科室余号查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.depOrderSourceRemain")
    public ResponseVO<List<QueryDepOrderSourceRemainResponseData>> queryDepOrderSourceRemain(QueryDepOrderSourceRemainRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryDepOrderSourceRemain(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDepOrderSourceRemain(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 科室医生查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.depDoctorList")
    public ResponseVO<PageVO<QueryDepDoctorListResponseData>> queryDepDoctorList(QueryDepDoctorListRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryDepDoctorList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDepDoctorList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 医生分时排班信息查询 (todo: 这个接口是后面添加的，是自定义的，通过代理过不来)
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.doctorScheduleList")
    public ResponseVO<List<QueryDoctorScheduleListResponseData>> getDoctorScheduleList(QueryDoctorScheduleListRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.getDoctorScheduleList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#getDoctorScheduleList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 医生号院查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.doctorOrderSourceList")
    public ResponseVO<List<QueryDoctorOrderSourceListResponseData>> queryDoctorOrderSourceList(QueryDoctorOrderSourceListRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryDoctorOrderSourceList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDoctorOrderSourceList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 院区列表查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.order.queryHospitalDistrictList")
    public ResponseVO<List<QueryHospitalDistrictListResponseData>> queryHospitalDistrictList(QueryHospitalDistrictListRequest request) throws Exception {
        try {
            return ResponseVO.success(isvRegisterService.queryHospitalDistrictList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryHospitalDistrictList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 排队列表查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.queue.queryList")
    public ResponseVO<List<QueryQueueListResponse>> queryQueueList(QueryQueueListRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryQueueList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryQueueList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 查询医生简介
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.doctor.doctorInfo")
    public ResponseVO<QueryDoctorInfoResponseData> queryDoctorInfo(QueryDoctorInfoRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryDoctorInfo(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDoctorInfo(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }

    /**
     * 医生科室列表查询
     *
     * @param request
     * @return
     */
    @PostMapping("isvRequest.other.doctorList")
    public ResponseVO<PageVO<QueryDoctorListResponseData>> queryDoctorDepartmentList(QueryDoctorListRequest request) {
        try {
            return ResponseVO.success(isvRegisterService.queryDoctorList(request));
        } catch (AppMessageException e) {
            return ResponseVO.fail(Code.RESP_CODE_PARAM_ERROR, e.getMessage());
        } catch (Exception e) {
            log.error("PlanController#queryDoctorDepartmentList(request = {}):\n {}", request, e.getMessage(), e);
            return ResponseVO.fail(Code.RESP_CODE_APP_EXCEPTION, e.getMessage());
        }
    }
}
