2025-10-07 22:32:54 +00:00
// ===----------------------------------------------------------------------===
//
// This source file is part of the Amiibo Service open source project
//
2026-03-22 23:39:48 +00:00
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
2025-10-07 22:32:54 +00:00
// Licensed under Apache license v2.0
//
2024-09-14 22:26:39 +00:00
// See LICENSE for license information
2025-10-07 22:32:54 +00:00
// See CONTRIBUTORS for the list of Amiibo Service project authors
2024-09-14 22:26:39 +00:00
//
2025-10-07 22:32:54 +00:00
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
2024-09-14 22:26:39 +00:00
import Foundation
2025-09-09 17:30:19 +00:00
/// A type that implements the service that uses a client to make calls.
2026-07-26 10:37:07 +02:00
///
/// This service forwards every call to the ``AmiiboClient`` client injected during initialization, which defaults to an ``AmiiboLiveClient`` instance. This type is `Sendable`, so an instance can be safely shared across concurrency domains.
2026-07-26 01:26:32 +02:00
public struct AmiiboService : Sendable {
2024-09-14 22:26:39 +00:00
// MARK: Properties
2025-09-09 17:30:19 +00:00
/// A client to interact with the endpoints.
2025-09-12 00:13:58 +00:00
private let client : any AmiiboClient
2024-09-14 22:26:39 +00:00
2025-09-09 17:30:19 +00:00
// MARK: Initializers
/// Initializes this service with a specific client type.
2025-09-12 00:13:58 +00:00
/// - Parameter client: A client to use to interact with the endpoints.
public init ( client : some AmiiboClient = AmiiboLiveClient ()) {
self . client = client
2024-09-14 22:26:39 +00:00
}
// MARK: Functions
2025-09-11 22:49:58 +00:00
2025-09-09 17:30:19 +00:00
/// Gets a list of amiibo items based on a given filter.
/// - Parameter filter: A filter to remove unwanted items from the result.
/// - Returns: A list of filtered amiibo items.
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
2024-09-14 22:26:39 +00:00
public func getAmiibos (
_ filter : AmiiboFilter = . init ()
2025-09-09 17:30:19 +00:00
) async throws ( AmiiboServiceError ) -> [ Amiibo ] {
2024-09-14 22:26:39 +00:00
try await client . getAmiibos ( by : filter )
}
2025-09-09 17:30:19 +00:00
/// Gets a list of amiibo series based on a given filter.
/// - Parameter filter: A filter to remove unwanted items from the result.
/// - Returns: A list of filtered amiibo series.
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
2024-09-14 22:26:39 +00:00
public func getAmiiboSeries (
_ filter : AmiiboSeriesFilter = . init ()
2025-09-09 17:30:19 +00:00
) async throws ( AmiiboServiceError ) -> [ AmiiboSeries ] {
2024-09-14 22:26:39 +00:00
try await client . getAmiiboSeries ( by : filter )
}
2025-09-09 17:30:19 +00:00
/// Gets a list of amiibo types based on a given filter.
/// - Parameter filter: A filter to remove unwanted items from the result.
/// - Returns: A list of filtered amiibo types.
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
2024-09-14 22:26:39 +00:00
public func getAmiiboTypes (
_ filter : AmiiboTypeFilter = . init ()
2025-09-09 17:30:19 +00:00
) async throws ( AmiiboServiceError ) -> [ AmiiboType ] {
2024-09-14 22:26:39 +00:00
try await client . getAmiiboTypes ( by : filter )
}
2025-09-09 17:30:19 +00:00
/// Gets a list of game characters based on a given filter.
/// - Parameter filter: A filter to remove unwanted items from the result.
/// - Returns: A list of filtered game characters.
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
2024-09-14 22:26:39 +00:00
public func getGameCharacters (
_ filter : GameCharacterFilter = . init ()
2025-09-09 17:30:19 +00:00
) async throws ( AmiiboServiceError ) -> [ GameCharacter ] {
2024-09-14 22:26:39 +00:00
try await client . getGameCharacters ( by : filter )
}
2025-09-09 17:30:19 +00:00
/// Gets a list of game series based on a given filter.
/// - Parameter filter: A filter to remove unwanted items from the result.
/// - Returns: A list of filtered game series.
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
2024-09-14 22:26:39 +00:00
public func getGameSeries (
_ filter : GameSeriesFilter = . init ()
2025-09-09 17:30:19 +00:00
) async throws ( AmiiboServiceError ) -> [ GameSeries ] {
2024-09-14 22:26:39 +00:00
try await client . getGameSeries ( by : filter )
}
2025-09-09 17:30:19 +00:00
/// Gets the date when the data was last updated.
2026-07-26 10:37:07 +02:00
/// - Returns: A last updated date, decoded as UTC.
2025-09-09 17:30:19 +00:00
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
public func getLastUpdated () async throws ( AmiiboServiceError ) -> Date {
2024-09-14 22:26:39 +00:00
try await client . getLastUpdated ()
}
}