//
//  DDGApiClientConfiguration.swift
//  CharacterViewer
//
//  Created by Connor Crawford on 6/5/19.
//  Copyright © 2019 Connor Crawford. All rights reserved.
//

import Foundation

/// An object containing the configuration parameters for a `DDGCharacterRepository`.
struct DDGCharacterRepositoryConfiguration {
    let url: URL
    let timeout: TimeInterval

    init(url: URL, timeout: TimeInterval) {
        self.url = url
        self.timeout = timeout
    }

    /// Initializes an instance of DDGCharacterRepositoryConfiguration with values populated from a configuration resource store.
    init?(resourceStore: ResourceStore = Bundle.main) {
        guard let urlString = resourceStore.object(forInfoDictionaryKey: "DDGApiUrl") as? String,
            let url = URL(string: urlString),
            let timeout = resourceStore.object(forInfoDictionaryKey: "DDGApiTimeout") as? Double
            else { return nil }
        
        self.init(
            url: url,
            timeout: timeout
        )
    }
}
