2023-04-23 13:57:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This source file is part of the AmiiboService open source project
|
|
|
|
//
|
|
|
|
// Copyright (c) 2023 Röck+Cöde VoF. and the AmiiboService project authors
|
|
|
|
// Licensed under the EUPL 1.2 or later.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for license information
|
|
|
|
// See CONTRIBUTORS.txt for the list of AmiiboService project authors
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2023-04-23 13:16:22 +00:00
|
|
|
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibos series (``AmiiboSeriesFilter``), amiibo types (``AmiiboTypeFilter``), characters (``CharacterFilter``), or game series (``GameSeriesFilter``).
|
2023-04-21 18:16:38 +00:00
|
|
|
public struct KeyNameFilter {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
private let key: String?
|
|
|
|
private let name: String?
|
|
|
|
|
|
|
|
// MARK: Initialisers
|
|
|
|
|
2023-04-23 13:16:22 +00:00
|
|
|
/// Initialises this filter.
|
|
|
|
/// - Parameters:
|
|
|
|
/// - key: A `key` value to match against.
|
|
|
|
/// - name: A `name` value to match against.
|
2023-04-21 18:16:38 +00:00
|
|
|
public init(
|
|
|
|
key: String? = nil,
|
|
|
|
name: String? = nil
|
|
|
|
) {
|
|
|
|
self.key = key
|
|
|
|
self.name = name
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-23 13:16:22 +00:00
|
|
|
// MARK: - Type aliases
|
|
|
|
|
|
|
|
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibos series.
|
|
|
|
public typealias AmiiboSeriesFilter = KeyNameFilter
|
|
|
|
|
|
|
|
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering amiibo types.
|
|
|
|
public typealias AmiiboTypeFilter = KeyNameFilter
|
|
|
|
|
|
|
|
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering characters.
|
|
|
|
public typealias CharacterFilter = KeyNameFilter
|
|
|
|
|
|
|
|
/// This filter provides all the possible parameters (and combinations) available at the remote API applies when filtering game series.
|
|
|
|
public typealias GameSeriesFilter = KeyNameFilter
|
|
|
|
|
2023-04-21 18:16:38 +00:00
|
|
|
// MARK: - Filter
|
|
|
|
|
|
|
|
extension KeyNameFilter: Filter {
|
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
|
|
|
func makeParameters() -> [String : String?] {
|
|
|
|
var parameters: [String : String?] = [:]
|
|
|
|
|
|
|
|
if let key {
|
|
|
|
parameters[.Key.key] = key
|
|
|
|
}
|
|
|
|
|
|
|
|
if let name {
|
|
|
|
parameters[.Key.name] = name
|
|
|
|
}
|
|
|
|
|
|
|
|
return parameters
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - String+Key
|
|
|
|
|
|
|
|
private extension String {
|
|
|
|
enum Key {
|
|
|
|
static let key = "key"
|
|
|
|
static let name = "name"
|
|
|
|
}
|
|
|
|
}
|