Files

87 lines
2.6 KiB
Swift
Raw Permalink Normal View History

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
//
// See LICENSE for license information
2025-10-07 22:32:54 +00:00
// See CONTRIBUTORS for the list of Amiibo Service project authors
//
2025-10-07 22:32:54 +00:00
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
import Foundation
/// A model that represents an amiibo.
2026-03-22 23:39:48 +00:00
public struct Amiibo: Sendable, Hashable {
// MARK: Properties
2026-03-22 23:39:48 +00:00
/// The name of the game character associated with this amiibo.
public let gameCharacter: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The name of the game series associated with this amiibo.
public let gameSeries: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The first 8 hexadecimal characters of the amiibo identifier.
public let head: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// A URL string pointing to the image of this amiibo.
public let image: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The name of this amiibo.
public let name: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The game platform data for this amiibo, if available.
public let platform: Platform?
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The release dates of this amiibo across different regions.
public let release: Release
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The name of the amiibo series this amiibo belongs to.
public let series: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The last 8 hexadecimal characters of the amiibo identifier.
public let tail: String
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// The type of this amiibo (e.g., Figure, Card, Yarn, Band).
public let type: String
2025-09-09 17:30:19 +00:00
// MARK: Initializers
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Amiibo) {
self.gameCharacter = payload.character
self.gameSeries = payload.gameSeries
self.head = payload.head
self.image = payload.image
self.name = payload.name
self.platform = .init(
payload.gamesSwitch,
payload.gamesSwitch2,
payload.games3DS,
payload.gamesWiiU
)
self.release = .init(payload.release)
self.series = payload.amiiboSeries
self.tail = payload.tail
self.type = payload._type
}
// MARK: Computed
2026-03-22 23:39:48 +00:00
/// The full 16-character hexadecimal identifier, composed of the ``head`` and ``tail``.
public var identifier: String {
head + tail
}
2026-03-22 23:39:48 +00:00
/// A URL constructed from the ``image`` string, if valid.
public var imageURL: URL? {
.init(string: image)
}
}