// // GetMemberInfoResponse.swift // SodaLive // // Created by klaus on 2023/08/10. // import Foundation enum MemberRole: String, Decodable { case USER, CREATOR, AGENT, ADMIN, BOT } struct GetMemberInfoResponse: Decodable { let can: Int let point: Int let isAuth: Bool let gender: String? let signupDate: String let chargeCount: Int let role: MemberRole let messageNotice: Bool? let followingChannelLiveNotice: Bool? let followingChannelUploadContentNotice: Bool? let auditionNotice: Bool? let countryCode: String let isAdultContentVisible: Bool let contentType: String enum CodingKeys: String, CodingKey { case can case point case isAuth case gender case signupDate case chargeCount case role case messageNotice case followingChannelLiveNotice case followingChannelUploadContentNotice case auditionNotice case countryCode case isAdultContentVisible case contentType } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) can = try container.decode(Int.self, forKey: .can) point = try container.decode(Int.self, forKey: .point) isAuth = try container.decode(Bool.self, forKey: .isAuth) gender = try container.decodeIfPresent(String.self, forKey: .gender) signupDate = try container.decode(String.self, forKey: .signupDate) chargeCount = try container.decode(Int.self, forKey: .chargeCount) role = try container.decode(MemberRole.self, forKey: .role) messageNotice = try container.decodeIfPresent(Bool.self, forKey: .messageNotice) followingChannelLiveNotice = try container.decodeIfPresent(Bool.self, forKey: .followingChannelLiveNotice) followingChannelUploadContentNotice = try container.decodeIfPresent(Bool.self, forKey: .followingChannelUploadContentNotice) auditionNotice = try container.decodeIfPresent(Bool.self, forKey: .auditionNotice) countryCode = try container .decodeIfPresent(String.self, forKey: .countryCode)? .trimmingCharacters(in: .whitespacesAndNewlines) .uppercased() ?? "" isAdultContentVisible = try container.decodeIfPresent(Bool.self, forKey: .isAdultContentVisible) ?? true let rawContentType = try container .decodeIfPresent(String.self, forKey: .contentType)? .trimmingCharacters(in: .whitespacesAndNewlines) .uppercased() contentType = ["ALL", "MALE", "FEMALE"].contains(rawContentType ?? "") ? (rawContentType ?? "ALL") : "ALL" } }