diff options
Diffstat (limited to 'Sora/Data/Booru/Provider')
| -rw-r--r-- | Sora/Data/Booru/Provider/BooruProviderCredentials.swift | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Sora/Data/Booru/Provider/BooruProviderCredentials.swift b/Sora/Data/Booru/Provider/BooruProviderCredentials.swift new file mode 100644 index 0000000..898201a --- /dev/null +++ b/Sora/Data/Booru/Provider/BooruProviderCredentials.swift @@ -0,0 +1,40 @@ +import Foundation + +struct BooruProviderCredentials: Codable, Identifiable, Equatable { + let id: UUID + let provider: BooruProvider + var apiKey: String + var userID: Int + + init(provider: BooruProvider, apiKey: String, userID: Int, id: UUID = UUID()) { + self.id = id + self.provider = provider + self.apiKey = apiKey + self.userID = userID + } + + static func from( + // swiftlint:disable:next large_tuple + _ rawCredentials: [(provider: BooruProvider, apiKey: String, userID: Int)], + existingCredentials: [Self] + ) -> [Self] { + rawCredentials.map { credentials in + if let existingKey = existingCredentials.first( + where: { $0.provider == credentials.provider } + ) { + return Self( + provider: credentials.provider, + apiKey: credentials.apiKey, + userID: credentials.userID, + id: existingKey.id + ) + } + + return Self( + provider: credentials.provider, + apiKey: credentials.apiKey, + userID: credentials.userID + ) + } + } +} |