//
//  HomeInteractor.swift
//  Synchronous
//
//  Created by Raymond Law on 2/22/18.
//  Copyright (c) 2018 Clean Swift LLC. 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

protocol HomeBusinessLogic
{
  var result: String { get }
  func stateVariable(request: Home.StateVariable.Request)
  func returnValue(request: Home.ReturnValue.Request) -> String
  func inOutParameter(request: Home.InOutParameter.Request, result: inout String)
  func completionHandler(request: Home.CompletionHandler.Request, completionHandler: (String) -> Void)
  func vipCycle(request: Home.VIPCycle.Request)
}

protocol HomeDataStore
{
}

class HomeInteractor: HomeBusinessLogic, HomeDataStore
{
  var presenter: HomePresentationLogic?
  var worker: HomeWorker?
  var result: String = ""
  
  // MARK: Use cases
  
  func stateVariable(request: Home.StateVariable.Request)
  {
    result = generateResult()
  }
  
  func returnValue(request: Home.ReturnValue.Request) -> String
  {
    return generateResult()
  }
  
  func inOutParameter(request: Home.InOutParameter.Request, result: inout String)
  {
    result = generateResult()
  }
  
  func completionHandler(request: Home.CompletionHandler.Request, completionHandler: (String) -> Void)
  {
    completionHandler(generateResult())
  }
  
  func vipCycle(request: Home.VIPCycle.Request)
  {
    let response = Home.VIPCycle.Response(result: generateResult())
    presenter?.presentVIPCycle(response: response)
  }
  
  private func generateResult() -> String
  {
    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .none
    dateFormatter.timeStyle = .medium
    let result = dateFormatter.string(from: Date())
    return result
  }
}
