 import Foundation
 
 
-// Logic
+/// Logic
 public
 enum URLRequesterEvent: Event {
-	case success(data: Data, response: URLResponse)
-	case failure(error: Error, response: URLResponse)
-
+	case success(request: URLRequest, data: Data, response: URLResponse)
+	case failure(request: URLRequest, error: Error)
+	
 	public
-	var response: URLResponse {
+	var request: URLRequest {
 		switch self {
-		case .success(let (_, response)), .failure(let (_, response)):
-			return response
+		case .success(let (request, _, _)):
+			return request
+		case .failure(let (request, _)):
+			return request
 		}
 	}
 }

public typealias URLRequesterState = Set<URLRequest>


// Implementation
public final class URLRequester<State> {

	public init(store: Store<State>, lens: @escaping (State) -> URLRequesterState) {
		self.store = store
		unsubscribe = store.subscribe { [weak self] state in
			let requests = lens(state)
			self?.configure(using: requests)
		}
	}

	private let store: Store<State>
	private var unsubscribe: Unsubscriber?
	private var current: [URLRequest: URLSessionTask] = [:]

	private func configure(using target: URLRequesterState) {

//
//  URLRequester.swift
//  TinyRedux
//
//  Created by Daniel Tartaglia on 3/23/17.
//  Copyright © 2017 Daniel Tartaglia. All rights reserved.
