passepartout-apple/PassepartoutLibrary/Sources/PassepartoutProviders/Domain/ProviderServer.swift

106 lines
3.0 KiB
Swift
Raw Normal View History

2022-04-12 13:09:14 +00:00
//
// ProviderServer.swift
// Passepartout
//
// Created by Davide De Rosa on 3/15/22.
2024-01-14 13:34:21 +00:00
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
2022-04-12 13:09:14 +00:00
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Passepartout is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
import Foundation
import GenericJSON
2023-05-24 16:19:47 +00:00
import PassepartoutCore
2022-04-12 13:09:14 +00:00
2023-05-24 16:19:47 +00:00
public struct ProviderServer {
2022-04-12 13:09:14 +00:00
public struct Preset {
public let id: String
public let name: String
public let comment: String
public let vpnProtocol: VPNProtocolType
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let vpnConfiguration: JSON
2022-06-23 21:31:01 +00:00
public init(id: String, name: String, comment: String, vpnProtocol: VPNProtocolType, vpnConfiguration: JSON) {
self.id = id
self.name = name
self.comment = comment
self.vpnProtocol = vpnProtocol
self.vpnConfiguration = vpnConfiguration
}
2022-04-12 13:09:14 +00:00
}
public let providerMetadata: ProviderMetadata
public let id: String
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let apiId: String
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let categoryName: String
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let countryCode: String
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let extraCountryCodes: [String]?
2023-03-17 20:55:47 +00:00
public let localizedName: String?
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let serverIndex: Int?
2023-03-17 20:55:47 +00:00
public let tags: [String]?
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let hostname: String?
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
public let ipAddresses: [String]
public let presetIds: [String]
2022-06-23 21:31:01 +00:00
public private(set) var presets: [Preset]?
2023-03-17 20:55:47 +00:00
public init(providerMetadata: ProviderMetadata, id: String, apiId: String, categoryName: String, countryCode: String, extraCountryCodes: [String]?, localizedName: String?, serverIndex: Int?, tags: [String]?, hostname: String?, ipAddresses: [String], presetIds: [String]) {
2022-06-23 21:31:01 +00:00
self.providerMetadata = providerMetadata
self.id = id
self.apiId = apiId
self.categoryName = categoryName
self.countryCode = countryCode
self.extraCountryCodes = extraCountryCodes
self.localizedName = localizedName
2022-06-23 21:31:01 +00:00
self.serverIndex = serverIndex
self.tags = tags
2022-06-23 21:31:01 +00:00
self.hostname = hostname
self.ipAddresses = ipAddresses
self.presetIds = presetIds
}
2023-05-24 16:19:47 +00:00
}
2022-04-12 13:09:14 +00:00
2023-05-24 16:19:47 +00:00
extension ProviderServer {
2022-04-12 13:09:14 +00:00
public func preset(withId presetId: String) -> Preset? {
2022-09-04 18:09:31 +00:00
presets?.first {
2022-04-12 13:09:14 +00:00
$0.id == presetId
}
}
2023-03-17 20:55:47 +00:00
2022-06-23 21:31:01 +00:00
public func withPresets(_ presets: [Preset]?) -> Self {
var copy = self
copy.presets = presets
return copy
2022-04-12 13:09:14 +00:00
}
}