//
//  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()
    
    func tokenHeader() -> HTTPHeader {
        let httpHeader = HTTPHeader.init(name: "Authorization", value: USER.token ?? "")
        return httpHeader
    }
    
    func loginCode(parameters:Encodable) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.verifyCode,parameters: parameters,encoding: JSONParameterEncoder.default,responseType: ResponseModel<String>.self)
    }
    
    func login(parameters:Encodable) -> Single<ResponseModel<LoginDataModel>?> {
        return DDAF.post(urlString: HOST+API.login,parameters: parameters,headers: ["Authorization":"Basic c3VwcGxpZXItYXBwOiQyYSQxMCRXZ1pIdzVSamoxcGpIYnJucG00YlYuTWlTZ0o2aWpzYWlNeHN2OUhwZWlYR094UWtWRWVaNg=="],responseType: ResponseModel<LoginDataModel>.self)
    }
    
    func logout(parameters:Encodable) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.logout,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func orderList(parameters:Encodable) -> Single<ResponseModel<[OrderListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.orderList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[OrderListDataModel]>.self)
    }
    
    func acceptDispatch(parameters:Encodable) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.acceptDispatch,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func refuseDispatch(parameters:Encodable) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.refuseDispatch,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func orderReport(parameters:Encodable) -> Single<ResponseModel<String>?> {
        return DDAF.post(urlString: HOST+API.orderReport,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<String>.self)
    }
    
    func dispatchVehicleList(parameters:Encodable) -> Single<ResponseModel<[DispatchVehicleListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.dispatchVehicleList,parameters: parameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[DispatchVehicleListDataModel]>.self)
    }
    
    func dispatchVehicle(parameters:Encodable) -> 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 getRtspChannel(prameters:Encodable) -> Single<ResponseModel<[String]>?> {
        return DDAF.post(urlString: HOST+API.getRtspChannel,parameters: prameters,encoding: URLEncodedFormParameterEncoder(destination: .httpBody),headers: [tokenHeader()],responseType: ResponseModel<[String]>.self)
    }
    
    func orderPhotoList(prameters:Encodable) -> Single<ResponseModel<[OrderPhotoListDataModel]>?> {
        return DDAF.post(urlString: HOST+API.orderPhotoList,parameters: prameters,encoding: JSONParameterEncoder.default,headers: [tokenHeader()],responseType: ResponseModel<[OrderPhotoListDataModel]>.self)
    }
    
    func supplementOrderPhoto(prameters:Encodable,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)
    }
}
