Files
amiibo-service/Sources/AmiiboService/Public/Models/Amiibo/Amiibo+Platform.swift
T

78 lines
2.7 KiB
Swift
Raw 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
//
// ===----------------------------------------------------------------------===
extension Amiibo {
/// A model that groups the games related to an amiibo by platform.
public struct Platform: Sendable, Hashable, Codable {
// MARK: Properties
/// A list of `Switch` games related to an amiibo.
public let `switch`: [Game]
/// A list of `Switch 2` games related to an amiibo.
public let switch2: [Game]
2025-09-09 17:30:19 +00:00
/// A list of `3DS` games related to an amiibo.
public let threeDS: [Game]
2025-09-09 17:30:19 +00:00
2026-03-22 23:39:48 +00:00
/// A list of `Wii U` games related to an amiibo.
public let wiiU: [Game]
// MARK: Initializers
2025-09-09 17:30:19 +00:00
/// Initializes this model.
package init(
`switch`: [Game] = [],
switch2: [Game] = [],
threeDS: [Game] = [],
wiiU: [Game] = []
) {
self.switch = `switch`
self.switch2 = switch2
self.threeDS = threeDS
self.wiiU = wiiU
}
/// Initializes this model from the given payloads.
2025-09-09 17:30:19 +00:00
///
/// > important: In case no data is provided, then an instance of this model is not created.
///
/// - Parameters:
/// - switch: A list of `Switch` games related to an amiibo, if any.
/// - switch2: A list of `Switch 2` games related to an amiibo, if any.
/// - threeDS: A list of `3DS` games related to an amiibo, if any.
2026-03-22 23:39:48 +00:00
/// - wiiU: A list of `Wii U` games related to an amiibo, if any.
init?(
_ `switch`: [Components.Schemas.AmiiboGame]?,
_ switch2: [Components.Schemas.AmiiboGame]?,
_ threeDS: [Components.Schemas.AmiiboGame]?,
_ wiiU: [Components.Schemas.AmiiboGame]?
) {
guard `switch`?.isEmpty == false
|| switch2?.isEmpty == false
|| threeDS?.isEmpty == false
|| wiiU?.isEmpty == false
else {
return nil
}
self.switch = `switch`?.map { .init($0) } ?? []
self.switch2 = switch2?.map { .init($0) } ?? []
self.threeDS = threeDS?.map { .init($0) } ?? []
self.wiiU = wiiU?.map { .init($0) } ?? []
}
}
}