 import RxSwift
 import RxAlamofire
 
+/// Enum that represents wrong usage of requset parameters
+///
+/// - getMethodForbidden: invalid usage of get method
+/// - urlEncodingForbidden: invalid usage of URLEncoding
+enum RequestUsageError: Error {
+    
+    case getMethodForbidden
+    case urlEncodingForbidden
+    
+}
+
 public extension Reactive where Base: SessionManager {
 
     

    public func request(_ method: Alamofire.HTTPMethod,
                        _ url: URLConvertible,
                        parameters: [Any]? = nil,
                        encoding: ParameterEncoding = JSONEncoding.default,
                        headers: [String: String]? = nil)
        -> Observable<DataRequest> {

        return Observable.deferred {
            let urlRequest = try URLRequest(url: try url.asURL(), method: method, headers: headers)

            if let encoding = encoding as? JSONEncoding {
                let encodedUrlRequest = try encoding.encode(urlRequest, withJSONObject: parameters)
                self.request(urlRequest: encodedUrlRequest)
            } else {
                assertionFailure("Invalid encoding type")
            }

            if method == .get {
                assertionFailure("Unable to pass array in get request")
            }

            return self.request(urlRequest: urlRequest)
        }
    }
    

                                        encoding: requestParameters.encoding,
                                        headers: requestParameters.headers)
        case .array(let parameters)?:
            if let encoding = requestParameters.encoding as? JSONEncoding {
                requestObservable = request(requestParameters.method,
                                            requestParameters.url,
                                            parameters: parameters,
                                            encoding: encoding,
                                            headers: requestParameters.headers)
            } else {
                assertionFailure("Invalid encoding type with array parameter")
                requestObservable = .error(RequestUsageError.urlEncodingForbidden)
            }
        case .none:
            requestObservable = request(requestParameters.method,
                                        requestParameters.url,
