//
//  RequestList.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/7.
//

import Foundation
import RxSwift
import DDNetworkingOfAlamofireKit_Private
import Alamofire

public let RQ = RequestList.default

open class RequestList {
    public static let `default` = RequestList()
    
    struct DDError : Error {
    }
    
    func tokenHeader() -> HTTPHeader {
        let httpHeader = HTTPHeader.init(name: "Authorization", value: USER.token ?? "")
        return httpHeader
    }
    
    func loginCode<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.verifyCode,parameters: parameters,encoding: JSONParameterEncoder.default,responseType: ResponseModel<String>.self)
    }
    
    func checkLogin<P:Encodable>(parameters:P) ->  Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.checkLogin,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [],responseType: ResponseModel<String>.self)
    }
    
    func login<P:Encodable>(parameters:P) -> Single<ResponseModel<LoginDataModel>?> {
        return DDAF.post(urlString: HOST+API.login,parameters: parameters,headers: ["Authorization":"Basic c3VwcGxpZXItYXBwOiQyYSQxMCRXZ1pIdzVSamoxcGpIYnJucG00YlYuTWlTZ0o2aWpzYWlNeHN2OUhwZWlYR094UWtWRWVaNg=="],responseType: ResponseModel<LoginDataModel>.self)
    }
    
    func token<P:Encodable>(parameters:P) -> Single<ResponseModel<LoginDataModel>?> {
        return DDAF.post(urlString: HOST+API.token,parameters: parameters,headers: ["Authorization":"Basic c3VwcGxpZXItYXBwOiQyYSQxMCRXZ1pIdzVSamoxcGpIYnJucG00YlYuTWlTZ0o2aWpzYWlNeHN2OUhwZWlYR094UWtWRWVaNg=="],responseType: ResponseModel<LoginDataModel>.self)
    }
    
    func logout<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.logout,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func orderList<P:Encodable>(parameters:P) -> Single<ResponseModel<[OrderListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.orderList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[OrderListDataModel]>.self)
    }
    
    func acceptDispatch<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.acceptDispatch,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func refuseDispatch<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.refuseDispatch,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func orderReport<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.orderReport,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func dispatchVehicleList<P:Encodable>(parameters:P) -> Single<ResponseModel<[DispatchVehicleListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.dispatchVehicleList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[DispatchVehicleListDataModel]>.self)
    }
    
    func dispatchVehicle<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.dispatchVehicle,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func toDoMessageCount() -> Single<ResponseModel<ToDoMessageCountDataModel>?> {
        return DDAF.post(urlString: HOST+API.toDoMessageCount,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<ToDoMessageCountDataModel>.self)
    }
    
    func vehicleMonitorList() -> Single<ResponseModel<VehicleMonitorListDataModel>?> {
        return DDAF.post(urlString: HOST+API.vehicleMonitorList,encoding: URLEncodedFormParameterEncoder(destination: .httpBody),headers: [tokenHeader()],responseType: ResponseModel<VehicleMonitorListDataModel>.self)
    }
    
    func getRealtimeUrl<P:Encodable>(prameters:P) -> Single<ResponseModel<GetVideoUrlDataModel>?> {
        return DDAF.post(urlString: HOST+API.getRealtimeUrl,parameters: prameters,encoding: URLEncodedFormParameterEncoder(destination: .httpBody),headers: [tokenHeader()],responseType: ResponseModel<GetVideoUrlDataModel>.self)
    }
    
    func getReplayUrl<P:Encodable>(prameters:P) -> Single<ResponseModel<GetVideoUrlDataModel>?> {
        return DDAF.post(urlString: HOST+API.getReplayUrl,parameters: prameters,encoding: URLEncodedFormParameterEncoder(destination: .httpBody),headers: [tokenHeader()],responseType: ResponseModel<GetVideoUrlDataModel>.self)
    }
    
    func closeHistoryControl<P:Encodable>(prameters:P) -> Single<ResponseModel<GetVideoUrlDataModel>?> {
        return DDAF.post(urlString: HOST+API.closeHistoryControl,parameters: prameters,encoding: URLEncodedFormParameterEncoder(destination: .httpBody),headers: [tokenHeader()],responseType: ResponseModel<GetVideoUrlDataModel>.self)
    }
    
    func orderPhotoList<P:Encodable>(prameters:P) -> Single<ResponseModel<[OrderPhotoListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.orderPhotoList,parameters: prameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[OrderPhotoListDataModel]>.self)
    }
    
    func supplementOrderPhoto<P:Encodable>(prameters:P,multipartFormData: @escaping (MultipartFormData) -> Void,uploadProgress: @escaping (Progress) -> Void) -> Single<ResponseModel<String>?> {
        return DDAF.upload(urlString: HOST+API.supplementOrderPhoto, headers: [tokenHeader()], responseType: ResponseModel<String>.self,multipartFormData: multipartFormData,uploadProgress: uploadProgress)
    }
    
    func generalInfo() -> Single<ResponseModel<GeneralInfoDataModel>?> {
        return DDAF.post(urlString: HOST+API.generalInfo,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<GeneralInfoDataModel>.self)
    }
    
    func getNeedConfirmPersonInfo<P:Encodable>(prameters:P) -> Single<ResponseModel<[NeedConfirmPersonInfoDataModel]>?> {
        return DDAF.get(urlString: HOST+API.getNeedConfirmPersonInfo,parameters: prameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[NeedConfirmPersonInfoDataModel]>.self)
    }
    
    func judgeIfNeedConfirm<P:Encodable>(prameters:P) -> Single<ResponseModel<JudgeIfNeedConfirmDataModel>?> {
        return DDAF.get(urlString: HOST+API.judgeIfNeedConfirm,parameters: prameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<JudgeIfNeedConfirmDataModel>.self)
    }
    
    func giveUp<P:Encodable>(prameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.get(urlString: HOST+API.giveUp,parameters: prameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func dispatchAppH5Urls() ->  Single<ResponseModel<DispatchAppH5UrlDataModel>?> {
        return DDAF.post(urlString: HOST+API.dispatchAppH5Urls,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<DispatchAppH5UrlDataModel>.self)
    }
    
    func updateVersion<P:Encodable>(parameters:P) -> Single<ResponseModel<UpdateVersionDataModel>?> {
        return DDAF.post(urlString: HOST+API.updateVersion,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<UpdateVersionDataModel>.self)
    }
    
    func messageReminderList<P:Encodable>(parameters:P) -> Single<ResponseModel<[MessageReminderListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.messageReminderList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[MessageReminderListDataModel]>.self)
    }
    
    func readMessageReminder<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.readMessageReminder,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func uploadCallRecord<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.uploadCallRecord,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func userOperationPermissions() -> Single<ResponseModel<[String]>?> {
        return DDAF.post(urlString: HOST+API.userOperationPermissions,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[String]>.self) { single, response in
            if response.value?.success == true {
                single(.success(response.value))
            }else{
                single(.failure(DDError()))
            }
        }
    }
    
    func vehicleLogout<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.vehicleLogout,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func jumpNewTrain() -> Single<ResponseModel<JumpPageDataModel>?> {
        return DDAF.post(urlString: HOST+API.jumpNewTrain,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<JumpPageDataModel>.self)
    }
    
    func giveUpUserOrder<P:Encodable>(parameters:P) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.giveUpUserOrder,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func appPushRecordList() -> Single<ResponseModel<[AppPushRecordListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.appPushRecordList,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[AppPushRecordListDataModel]>.self)
    }
    
    func getConfigByCode<P:Encodable>(parameters:P) -> Single<ResponseModel<ConfigByCodeDataModel>?> {
        return DDAF.post(urlString: HOST+API.getConfigByCode,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<ConfigByCodeDataModel>.self)
    }
    
    func thisWeekNumber()-> Single<ResponseModel<Int>?> {
        return DDAF.get(urlString: HOST+API.thisWeekNumber,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<Int>.self)
    }
    
    func alarmList<P:Encodable>(parameters:P) -> Single<ResponseModel<[AlarmListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.alarmList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[AlarmListDataModel]>.self)
    }
    
    func getAlarmByCode<P:Encodable>(parameters:P) -> Single<ResponseModel<GetAlarmByCodeDataModel>?> {
        return DDAF.post(urlString: HOST+API.getAlarmByCode,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<GetAlarmByCodeDataModel>.self)
    }
    
    func getAppeal<P:Encodable>(parameters:P) -> Single<ResponseModel<GetAppealDataModel>?> {
        return DDAF.get(urlString: HOST+API.getAppeal,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<GetAppealDataModel>.self)
    }
    
    func saveAppeal<P:Encodable>(parameters:P) -> Single<ResponseModel<SaveAppealModel>?> {
        return DDAF.get(urlString: HOST+API.saveAppeal,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<SaveAppealModel>.self)
    }
    
    func onlineReminder<P:Encodable>(parameters:P) -> Single<ResponseModel<MessageReminderListDataModel>?> {
        return DDAF.get(urlString: HOST+API.onlineReminder,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<MessageReminderListDataModel>.self)
    }
    
    func vehicleMonitorInfo<P:Encodable>(parameters:P) -> Single<ResponseModel<VehicleMonitorInfoDataModel>?> {
        return DDAF.post(urlString: HOST+API.vehicleMonitorInfo,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<VehicleMonitorInfoDataModel>.self)
    }
    
    func selectCountBySupplierId<P:Encodable>(parameters:P) -> Single<ResponseModel<Int>?> {
        return DDAF.get(urlString: HOST+API.selectCountBySupplierId,parameters: parameters,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<Int>.self)
    }
    
    func gjTokenInfo() -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.gjTokenInfo,encoding: URLEncodedFormParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
}
