//
//  RoverPhotosWorker.swift
//  NASA Probes
//
//  Created by Matheus Cardoso kuhn on 19/04/19.
//  Copyright (c) 2019 MDT. All rights reserved.
//
//  This file was generated by the Clean Swift Xcode Templates so
//  you can apply clean architecture to your iOS and Mac projects,
//  see http://clean-swift.com
//

import UIKit
import Alamofire

class RoverPhotosWorker {
    func requestPhotos(roverName: String, earthDate: String, completion: @escaping (_ result: Result<Photos>) -> Void) {
        let parameters = ["earth_date": earthDate,
                          "api_key": "l0cZ7ls0LbAEFI6h75Upbh1Y7tL9wmucSWQ2QK8P"]
        ConnectionUtil.request(on: "rovers/\(roverName)/photos",
                               method: HTTPMethod.get,
                               parameters: parameters) { (result: Result<Photos>) in
                                completion(result)
        }
    }
    
    func downloadPhoto(on url: String, completion: @escaping (_ result: Result<UIImage>) -> Void) {
        ConnectionUtil.downloadImage(on: url) { (result: Result<UIImage>) in
            completion(result)
        }
    }
}
