import Foundation import JSONCodable /// Project open class Project: Codable { enum CodingKeys: String, CodingKey { case id = "$id" case createdAt = "$createdAt" case updatedAt = "$updatedAt" case name = "name" case teamId = "teamId" case region = "region" case devKeys = "devKeys" case smtpEnabled = "smtpEnabled" case smtpSenderName = "smtpSenderName" case smtpSenderEmail = "smtpSenderEmail" case smtpReplyToName = "smtpReplyToName" case smtpReplyToEmail = "smtpReplyToEmail" case smtpHost = "smtpHost" case smtpPort = "smtpPort" case smtpUsername = "smtpUsername" case smtpPassword = "smtpPassword" case smtpSecure = "smtpSecure" case pingCount = "pingCount" case pingedAt = "pingedAt" case labels = "labels" case status = "status" case authMethods = "authMethods" case services = "services" case protocols = "protocols" case blocks = "blocks" case consoleAccessedAt = "consoleAccessedAt" case billingLimits = "billingLimits" case oAuth2ServerEnabled = "oAuth2ServerEnabled" case oAuth2ServerAuthorizationUrl = "oAuth2ServerAuthorizationUrl" case oAuth2ServerScopes = "oAuth2ServerScopes" case oAuth2ServerAccessTokenDuration = "oAuth2ServerAccessTokenDuration" case oAuth2ServerRefreshTokenDuration = "oAuth2ServerRefreshTokenDuration" case oAuth2ServerPublicAccessTokenDuration = "oAuth2ServerPublicAccessTokenDuration" case oAuth2ServerPublicRefreshTokenDuration = "oAuth2ServerPublicRefreshTokenDuration" case oAuth2ServerConfidentialPkce = "oAuth2ServerConfidentialPkce" case oAuth2ServerDiscoveryUrl = "oAuth2ServerDiscoveryUrl" } /// Project ID. public let id: String /// Project creation date in ISO 8601 format. public let createdAt: String /// Project update date in ISO 8601 format. public let updatedAt: String /// Project name. public let name: String /// Project team ID. public let teamId: String /// Project region public let region: String /// Deprecated since 1.9.5: List of dev keys. public let devKeys: [DevKey] /// Status for custom SMTP public let smtpEnabled: Bool /// SMTP sender name public let smtpSenderName: String /// SMTP sender email public let smtpSenderEmail: String /// SMTP reply to name public let smtpReplyToName: String /// SMTP reply to email public let smtpReplyToEmail: String /// SMTP server host name public let smtpHost: String /// SMTP server port public let smtpPort: Int /// SMTP server username public let smtpUsername: String /// SMTP server password. This property is write-only and always returned empty. public let smtpPassword: String /// SMTP server secure protocol public let smtpSecure: String /// Number of times the ping was received for this project. public let pingCount: Int /// Last ping datetime in ISO 8601 format. public let pingedAt: String /// Labels for the project. public let labels: [String] /// Project status public let status: String /// List of auth methods. public let authMethods: [ProjectAuthMethod] /// List of services. public let services: [ProjectService] /// List of protocols. public let protocols: [ProjectProtocol] /// Project blocks information public let blocks: [Block] /// Last time the project was accessed via console. Used with plan's projectInactivityDays to determine if project is paused. public let consoleAccessedAt: String /// Billing limits reached public let billingLimits: BillingLimits? /// OAuth2 server status public let oAuth2ServerEnabled: Bool /// OAuth2 server authorization URL public let oAuth2ServerAuthorizationUrl: String /// OAuth2 server allowed scopes public let oAuth2ServerScopes: [String] /// OAuth2 server access token duration in seconds for confidential clients public let oAuth2ServerAccessTokenDuration: Int /// OAuth2 server refresh token duration in seconds for confidential clients public let oAuth2ServerRefreshTokenDuration: Int /// OAuth2 server access token duration in seconds for public clients (SPAs, mobile, native) public let oAuth2ServerPublicAccessTokenDuration: Int /// OAuth2 server refresh token duration in seconds for public clients (SPAs, mobile, native) public let oAuth2ServerPublicRefreshTokenDuration: Int /// When enabled, PKCE is required for confidential clients (server-side flows using client_secret). PKCE is always required for public clients regardless of this setting. public let oAuth2ServerConfidentialPkce: Bool /// OAuth2 server discovery URL public let oAuth2ServerDiscoveryUrl: String init( id: String, createdAt: String, updatedAt: String, name: String, teamId: String, region: String, devKeys: [DevKey], smtpEnabled: Bool, smtpSenderName: String, smtpSenderEmail: String, smtpReplyToName: String, smtpReplyToEmail: String, smtpHost: String, smtpPort: Int, smtpUsername: String, smtpPassword: String, smtpSecure: String, pingCount: Int, pingedAt: String, labels: [String], status: String, authMethods: [ProjectAuthMethod], services: [ProjectService], protocols: [ProjectProtocol], blocks: [Block], consoleAccessedAt: String, billingLimits: BillingLimits?, oAuth2ServerEnabled: Bool, oAuth2ServerAuthorizationUrl: String, oAuth2ServerScopes: [String], oAuth2ServerAccessTokenDuration: Int, oAuth2ServerRefreshTokenDuration: Int, oAuth2ServerPublicAccessTokenDuration: Int, oAuth2ServerPublicRefreshTokenDuration: Int, oAuth2ServerConfidentialPkce: Bool, oAuth2ServerDiscoveryUrl: String ) { self.id = id self.createdAt = createdAt self.updatedAt = updatedAt self.name = name self.teamId = teamId self.region = region self.devKeys = devKeys self.smtpEnabled = smtpEnabled self.smtpSenderName = smtpSenderName self.smtpSenderEmail = smtpSenderEmail self.smtpReplyToName = smtpReplyToName self.smtpReplyToEmail = smtpReplyToEmail self.smtpHost = smtpHost self.smtpPort = smtpPort self.smtpUsername = smtpUsername self.smtpPassword = smtpPassword self.smtpSecure = smtpSecure self.pingCount = pingCount self.pingedAt = pingedAt self.labels = labels self.status = status self.authMethods = authMethods self.services = services self.protocols = protocols self.blocks = blocks self.consoleAccessedAt = consoleAccessedAt self.billingLimits = billingLimits self.oAuth2ServerEnabled = oAuth2ServerEnabled self.oAuth2ServerAuthorizationUrl = oAuth2ServerAuthorizationUrl self.oAuth2ServerScopes = oAuth2ServerScopes self.oAuth2ServerAccessTokenDuration = oAuth2ServerAccessTokenDuration self.oAuth2ServerRefreshTokenDuration = oAuth2ServerRefreshTokenDuration self.oAuth2ServerPublicAccessTokenDuration = oAuth2ServerPublicAccessTokenDuration self.oAuth2ServerPublicRefreshTokenDuration = oAuth2ServerPublicRefreshTokenDuration self.oAuth2ServerConfidentialPkce = oAuth2ServerConfidentialPkce self.oAuth2ServerDiscoveryUrl = oAuth2ServerDiscoveryUrl } public required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.id = try container.decode(String.self, forKey: .id) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) self.name = try container.decode(String.self, forKey: .name) self.teamId = try container.decode(String.self, forKey: .teamId) self.region = try container.decode(String.self, forKey: .region) self.devKeys = try container.decode([DevKey].self, forKey: .devKeys) self.smtpEnabled = try container.decode(Bool.self, forKey: .smtpEnabled) self.smtpSenderName = try container.decode(String.self, forKey: .smtpSenderName) self.smtpSenderEmail = try container.decode(String.self, forKey: .smtpSenderEmail) self.smtpReplyToName = try container.decode(String.self, forKey: .smtpReplyToName) self.smtpReplyToEmail = try container.decode(String.self, forKey: .smtpReplyToEmail) self.smtpHost = try container.decode(String.self, forKey: .smtpHost) self.smtpPort = try container.decode(Int.self, forKey: .smtpPort) self.smtpUsername = try container.decode(String.self, forKey: .smtpUsername) self.smtpPassword = try container.decode(String.self, forKey: .smtpPassword) self.smtpSecure = try container.decode(String.self, forKey: .smtpSecure) self.pingCount = try container.decode(Int.self, forKey: .pingCount) self.pingedAt = try container.decode(String.self, forKey: .pingedAt) self.labels = try container.decode([String].self, forKey: .labels) self.status = try container.decode(String.self, forKey: .status) self.authMethods = try container.decode([ProjectAuthMethod].self, forKey: .authMethods) self.services = try container.decode([ProjectService].self, forKey: .services) self.protocols = try container.decode([ProjectProtocol].self, forKey: .protocols) self.blocks = try container.decode([Block].self, forKey: .blocks) self.consoleAccessedAt = try container.decode(String.self, forKey: .consoleAccessedAt) self.billingLimits = try container.decodeIfPresent(BillingLimits.self, forKey: .billingLimits) self.oAuth2ServerEnabled = try container.decode(Bool.self, forKey: .oAuth2ServerEnabled) self.oAuth2ServerAuthorizationUrl = try container.decode(String.self, forKey: .oAuth2ServerAuthorizationUrl) self.oAuth2ServerScopes = try container.decode([String].self, forKey: .oAuth2ServerScopes) self.oAuth2ServerAccessTokenDuration = try container.decode(Int.self, forKey: .oAuth2ServerAccessTokenDuration) self.oAuth2ServerRefreshTokenDuration = try container.decode(Int.self, forKey: .oAuth2ServerRefreshTokenDuration) self.oAuth2ServerPublicAccessTokenDuration = try container.decode(Int.self, forKey: .oAuth2ServerPublicAccessTokenDuration) self.oAuth2ServerPublicRefreshTokenDuration = try container.decode(Int.self, forKey: .oAuth2ServerPublicRefreshTokenDuration) self.oAuth2ServerConfidentialPkce = try container.decode(Bool.self, forKey: .oAuth2ServerConfidentialPkce) self.oAuth2ServerDiscoveryUrl = try container.decode(String.self, forKey: .oAuth2ServerDiscoveryUrl) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) try container.encode(name, forKey: .name) try container.encode(teamId, forKey: .teamId) try container.encode(region, forKey: .region) try container.encode(devKeys, forKey: .devKeys) try container.encode(smtpEnabled, forKey: .smtpEnabled) try container.encode(smtpSenderName, forKey: .smtpSenderName) try container.encode(smtpSenderEmail, forKey: .smtpSenderEmail) try container.encode(smtpReplyToName, forKey: .smtpReplyToName) try container.encode(smtpReplyToEmail, forKey: .smtpReplyToEmail) try container.encode(smtpHost, forKey: .smtpHost) try container.encode(smtpPort, forKey: .smtpPort) try container.encode(smtpUsername, forKey: .smtpUsername) try container.encode(smtpPassword, forKey: .smtpPassword) try container.encode(smtpSecure, forKey: .smtpSecure) try container.encode(pingCount, forKey: .pingCount) try container.encode(pingedAt, forKey: .pingedAt) try container.encode(labels, forKey: .labels) try container.encode(status, forKey: .status) try container.encode(authMethods, forKey: .authMethods) try container.encode(services, forKey: .services) try container.encode(protocols, forKey: .protocols) try container.encode(blocks, forKey: .blocks) try container.encode(consoleAccessedAt, forKey: .consoleAccessedAt) try container.encodeIfPresent(billingLimits, forKey: .billingLimits) try container.encode(oAuth2ServerEnabled, forKey: .oAuth2ServerEnabled) try container.encode(oAuth2ServerAuthorizationUrl, forKey: .oAuth2ServerAuthorizationUrl) try container.encode(oAuth2ServerScopes, forKey: .oAuth2ServerScopes) try container.encode(oAuth2ServerAccessTokenDuration, forKey: .oAuth2ServerAccessTokenDuration) try container.encode(oAuth2ServerRefreshTokenDuration, forKey: .oAuth2ServerRefreshTokenDuration) try container.encode(oAuth2ServerPublicAccessTokenDuration, forKey: .oAuth2ServerPublicAccessTokenDuration) try container.encode(oAuth2ServerPublicRefreshTokenDuration, forKey: .oAuth2ServerPublicRefreshTokenDuration) try container.encode(oAuth2ServerConfidentialPkce, forKey: .oAuth2ServerConfidentialPkce) try container.encode(oAuth2ServerDiscoveryUrl, forKey: .oAuth2ServerDiscoveryUrl) } public func toMap() -> [String: Any] { return [ "$id": id as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "name": name as Any, "teamId": teamId as Any, "region": region as Any, "devKeys": devKeys.map { $0.toMap() } as Any, "smtpEnabled": smtpEnabled as Any, "smtpSenderName": smtpSenderName as Any, "smtpSenderEmail": smtpSenderEmail as Any, "smtpReplyToName": smtpReplyToName as Any, "smtpReplyToEmail": smtpReplyToEmail as Any, "smtpHost": smtpHost as Any, "smtpPort": smtpPort as Any, "smtpUsername": smtpUsername as Any, "smtpPassword": smtpPassword as Any, "smtpSecure": smtpSecure as Any, "pingCount": pingCount as Any, "pingedAt": pingedAt as Any, "labels": labels as Any, "status": status as Any, "authMethods": authMethods.map { $0.toMap() } as Any, "services": services.map { $0.toMap() } as Any, "protocols": protocols.map { $0.toMap() } as Any, "blocks": blocks.map { $0.toMap() } as Any, "consoleAccessedAt": consoleAccessedAt as Any, "billingLimits": billingLimits?.toMap() as Any, "oAuth2ServerEnabled": oAuth2ServerEnabled as Any, "oAuth2ServerAuthorizationUrl": oAuth2ServerAuthorizationUrl as Any, "oAuth2ServerScopes": oAuth2ServerScopes as Any, "oAuth2ServerAccessTokenDuration": oAuth2ServerAccessTokenDuration as Any, "oAuth2ServerRefreshTokenDuration": oAuth2ServerRefreshTokenDuration as Any, "oAuth2ServerPublicAccessTokenDuration": oAuth2ServerPublicAccessTokenDuration as Any, "oAuth2ServerPublicRefreshTokenDuration": oAuth2ServerPublicRefreshTokenDuration as Any, "oAuth2ServerConfidentialPkce": oAuth2ServerConfidentialPkce as Any, "oAuth2ServerDiscoveryUrl": oAuth2ServerDiscoveryUrl as Any ] } public static func from(map: [String: Any] ) -> Project { return Project( id: map["$id"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, name: map["name"] as! String, teamId: map["teamId"] as! String, region: map["region"] as! String, devKeys: (map["devKeys"] as! [[String: Any]]).map { DevKey.from(map: $0) }, smtpEnabled: map["smtpEnabled"] as! Bool, smtpSenderName: map["smtpSenderName"] as! String, smtpSenderEmail: map["smtpSenderEmail"] as! String, smtpReplyToName: map["smtpReplyToName"] as! String, smtpReplyToEmail: map["smtpReplyToEmail"] as! String, smtpHost: map["smtpHost"] as! String, smtpPort: map["smtpPort"] as! Int, smtpUsername: map["smtpUsername"] as! String, smtpPassword: map["smtpPassword"] as! String, smtpSecure: map["smtpSecure"] as! String, pingCount: map["pingCount"] as! Int, pingedAt: map["pingedAt"] as! String, labels: map["labels"] as! [String], status: map["status"] as! String, authMethods: (map["authMethods"] as! [[String: Any]]).map { ProjectAuthMethod.from(map: $0) }, services: (map["services"] as! [[String: Any]]).map { ProjectService.from(map: $0) }, protocols: (map["protocols"] as! [[String: Any]]).map { ProjectProtocol.from(map: $0) }, blocks: (map["blocks"] as! [[String: Any]]).map { Block.from(map: $0) }, consoleAccessedAt: map["consoleAccessedAt"] as! String, billingLimits: BillingLimits.from(map: map["billingLimits"] as! [String: Any]), oAuth2ServerEnabled: map["oAuth2ServerEnabled"] as! Bool, oAuth2ServerAuthorizationUrl: map["oAuth2ServerAuthorizationUrl"] as! String, oAuth2ServerScopes: map["oAuth2ServerScopes"] as! [String], oAuth2ServerAccessTokenDuration: map["oAuth2ServerAccessTokenDuration"] as! Int, oAuth2ServerRefreshTokenDuration: map["oAuth2ServerRefreshTokenDuration"] as! Int, oAuth2ServerPublicAccessTokenDuration: map["oAuth2ServerPublicAccessTokenDuration"] as! Int, oAuth2ServerPublicRefreshTokenDuration: map["oAuth2ServerPublicRefreshTokenDuration"] as! Int, oAuth2ServerConfidentialPkce: map["oAuth2ServerConfidentialPkce"] as! Bool, oAuth2ServerDiscoveryUrl: map["oAuth2ServerDiscoveryUrl"] as! String ) } }