//
//  LocationsService.swift
//  Locations
//
//  Created by Javier Cicchelli on 10/04/2023.
//  Copyright © 2023 Röck+Cöde. All rights reserved.
//

import APICore
import Foundation

public struct LocationsService {
    
    // MARK: Properties
    
    private let client: Client
    
    // MARK: Initialisers
    
    public init(configuration: URLSessionConfiguration = .default) {
        self.client = LocationsClient(configuration: configuration)
    }
    
    // MARK: Functions
    
    public func getLocations() async throws -> [Location] {
        try await client.request(
            endpoint: GetLocationsEndpoint(),
            for: Locations.self
        ).locations
    }

}

// MARK: - Models

struct Locations: Decodable, Equatable {
    public let locations: [Location]
}
