//
//  DebugLogInteractor.swift
//  xDrip
//
//  Created by Artem Kalmykov on 06.04.2020.
//  Copyright (c) 2020 Faifly. 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 DebugLogBusinessLogic {
    func doLoad(request: DebugLog.Load.Request)
}

protocol DebugLogDataStore: AnyObject {    
}

final class DebugLogInteractor: DebugLogBusinessLogic, DebugLogDataStore {
    var presenter: DebugLogPresentationLogic?
    var router: DebugLogRoutingLogic?
    
    // MARK: Do something
    
    func doLoad(request: DebugLog.Load.Request) {
        let response = DebugLog.Load.Response()
        presenter?.presentLoad(response: response)
        
        DebugController.shared.logSubscriber = { [weak self] in
            DispatchQueue.main.async { [weak self] in
                self?.updateLogs()
            }
        }
        
        updateLogs()
    }
    
    private func updateLogs() {
        let response = DebugLog.UpdateLog.Response(logs: DebugController.shared.logs)
        presenter?.presentLogs(response: response)
    }
}
