passepartout-apple/PassepartoutLibrary/Sources/PassepartoutCore/Models/ProviderServer.swift

103 lines
2.9 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.
2023-03-17 15:56:19 +00:00
// Copyright (c) 2023 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
public struct ProviderServer: Identifiable {
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
}
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
}
}