Manos Chorianopoulos

update ProfileModel

...@@ -39,6 +39,23 @@ public class ProfileModel: NSObject { ...@@ -39,6 +39,23 @@ public class ProfileModel: NSObject {
39 private var uuid: String? 39 private var uuid: String?
40 private var verified: Bool? 40 private var verified: Bool?
41 41
42 + // NEW: Missing API Response Fields
43 + private var user_segments: [String]?
44 + private var eligibility_type: String?
45 + private var favorite_couponsets: [String]?
46 + private var user_id: String?
47 + private var is_eligible: Bool?
48 + private var questionnaire: [String: Any]?
49 + private var user_answers: [QuestionnaireAnswerModel]?
50 + private var questionnaire_answers: [QuestionnaireAnswerModel]?
51 +
52 + // Enhanced profile_metadata fields
53 + private var username: String?
54 + private var contract_accounts: [String]?
55 + private var master_id: String?
56 + private var questionnaire_v2: [String: Any]?
57 + private var answered_count: Int?
58 +
42 // optin 59 // optin
43 private var optin_newsletter: Bool? 60 private var optin_newsletter: Bool?
44 private var optin_sms: Bool? 61 private var optin_sms: Bool?
...@@ -83,6 +100,23 @@ public class ProfileModel: NSObject { ...@@ -83,6 +100,23 @@ public class ProfileModel: NSObject {
83 self.uuid = "" 100 self.uuid = ""
84 self.verified = false 101 self.verified = false
85 102
103 + // NEW: Missing API Response Fields
104 + self.user_segments = []
105 + self.eligibility_type = ""
106 + self.favorite_couponsets = []
107 + self.user_id = ""
108 + self.is_eligible = false
109 + self.questionnaire = [String: Any]()
110 + self.user_answers = []
111 + self.questionnaire_answers = []
112 +
113 + // Enhanced profile_metadata fields
114 + self.username = ""
115 + self.contract_accounts = []
116 + self.master_id = ""
117 + self.questionnaire_v2 = [String: Any]()
118 + self.answered_count = 0
119 +
86 // optin 120 // optin
87 self.optin_newsletter = false 121 self.optin_newsletter = false
88 self.optin_sms = false 122 self.optin_sms = false
...@@ -126,6 +160,28 @@ public class ProfileModel: NSObject { ...@@ -126,6 +160,28 @@ public class ProfileModel: NSObject {
126 self.uuid = dictionary["uuid"] as? String? ?? "" 160 self.uuid = dictionary["uuid"] as? String? ?? ""
127 self.verified = dictionary["verified"] as? Bool? ?? false 161 self.verified = dictionary["verified"] as? Bool? ?? false
128 162
163 + // NEW: Missing API Response Fields
164 + self.user_segments = dictionary["user_segments"] as? [String] ?? []
165 + self.eligibility_type = dictionary["eligibility_type"] as? String ?? ""
166 + self.favorite_couponsets = dictionary["favorite_couponsets"] as? [String] ?? []
167 + self.user_id = dictionary["user_id"] as? String ?? ""
168 + self.is_eligible = dictionary["is_eligible"] as? Bool ?? false
169 + self.questionnaire = dictionary["questionnaire"] as? [String: Any] ?? [String: Any]()
170 +
171 + // Parse user_answers array
172 + if let userAnswersArray = dictionary["user_answers"] as? [[String: Any]] {
173 + self.user_answers = userAnswersArray.map { QuestionnaireAnswerModel(dictionary: $0) }
174 + } else {
175 + self.user_answers = []
176 + }
177 +
178 + // Parse questionnaire_answers array
179 + if let questionnaireAnswersArray = dictionary["questionnaire_answers"] as? [[String: Any]] {
180 + self.questionnaire_answers = questionnaireAnswersArray.map { QuestionnaireAnswerModel(dictionary: $0) }
181 + } else {
182 + self.questionnaire_answers = []
183 + }
184 +
129 // optin 185 // optin
130 let optin = dictionary["optin"] as? [String: Any]? ?? ["":""] 186 let optin = dictionary["optin"] as? [String: Any]? ?? ["":""]
131 self.optin_newsletter = optin?["newsletter"] as? Bool? ?? false 187 self.optin_newsletter = optin?["newsletter"] as? Bool? ?? false
...@@ -149,12 +205,26 @@ public class ProfileModel: NSObject { ...@@ -149,12 +205,26 @@ public class ProfileModel: NSObject {
149 self.msisdnList = (tempMsisdnList ?? []).filter { $0 != "" } 205 self.msisdnList = (tempMsisdnList ?? []).filter { $0 != "" }
150 self.answered = profile_metadata_parsed["answered"] as? Bool? ?? false 206 self.answered = profile_metadata_parsed["answered"] as? Bool? ?? false
151 self.nonTelco = profile_metadata_parsed["nonTelco"] as? Bool? ?? false 207 self.nonTelco = profile_metadata_parsed["nonTelco"] as? Bool? ?? false
208 +
209 + // Enhanced profile_metadata fields
210 + self.username = profile_metadata_parsed["username"] as? String? ?? ""
211 + self.contract_accounts = profile_metadata_parsed["contract_accounts"] as? [String] ?? []
212 + self.master_id = profile_metadata_parsed["master_id"] as? String? ?? ""
213 + self.questionnaire_v2 = profile_metadata_parsed["questionnaire_v2"] as? [String: Any] ?? [String: Any]()
214 + self.answered_count = profile_metadata_parsed["answered_count"] as? Int? ?? 0
152 } else { 215 } else {
153 self.profile_metadata = [String: Any]() 216 self.profile_metadata = [String: Any]()
154 self.badge = "" 217 self.badge = ""
155 self.msisdnList = [] 218 self.msisdnList = []
156 self.answered = false 219 self.answered = false
157 self.nonTelco = false 220 self.nonTelco = false
221 +
222 + // Enhanced profile_metadata fields defaults
223 + self.username = ""
224 + self.contract_accounts = []
225 + self.master_id = ""
226 + self.questionnaire_v2 = [String: Any]()
227 + self.answered_count = 0
158 print("bad json") 228 print("bad json")
159 } 229 }
160 } catch let error as NSError { 230 } catch let error as NSError {
...@@ -163,6 +233,13 @@ public class ProfileModel: NSObject { ...@@ -163,6 +233,13 @@ public class ProfileModel: NSObject {
163 self.msisdnList = [] 233 self.msisdnList = []
164 self.answered = false 234 self.answered = false
165 self.nonTelco = false 235 self.nonTelco = false
236 +
237 + // Enhanced profile_metadata fields defaults
238 + self.username = ""
239 + self.contract_accounts = []
240 + self.master_id = ""
241 + self.questionnaire_v2 = [String: Any]()
242 + self.answered_count = 0
166 print(error) 243 print(error)
167 } 244 }
168 245
...@@ -172,6 +249,13 @@ public class ProfileModel: NSObject { ...@@ -172,6 +249,13 @@ public class ProfileModel: NSObject {
172 self.msisdnList = [] 249 self.msisdnList = []
173 self.answered = false 250 self.answered = false
174 self.nonTelco = false 251 self.nonTelco = false
252 +
253 + // Enhanced profile_metadata fields defaults
254 + self.username = ""
255 + self.contract_accounts = []
256 + self.master_id = ""
257 + self.questionnaire_v2 = [String: Any]()
258 + self.answered_count = 0
175 } 259 }
176 260
177 } else { 261 } else {
...@@ -180,6 +264,13 @@ public class ProfileModel: NSObject { ...@@ -180,6 +264,13 @@ public class ProfileModel: NSObject {
180 self.msisdnList = [] 264 self.msisdnList = []
181 self.answered = false 265 self.answered = false
182 self.nonTelco = false 266 self.nonTelco = false
267 +
268 + // Enhanced profile_metadata fields defaults
269 + self.username = ""
270 + self.contract_accounts = []
271 + self.master_id = ""
272 + self.questionnaire_v2 = [String: Any]()
273 + self.answered_count = 0
183 } 274 }
184 } 275 }
185 276
...@@ -364,6 +455,73 @@ public class ProfileModel: NSObject { ...@@ -364,6 +455,73 @@ public class ProfileModel: NSObject {
364 set(newValue) { self.nonTelco = newValue } 455 set(newValue) { self.nonTelco = newValue }
365 } 456 }
366 457
458 + // MARK: - NEW Public Accessors for Missing API Response Fields
459 + public var _user_segments: [String] {
460 + get { return self.user_segments ?? [] }
461 + set(newValue) { self.user_segments = newValue }
462 + }
463 +
464 + public var _eligibility_type: String {
465 + get { return self.eligibility_type ?? "" }
466 + set(newValue) { self.eligibility_type = newValue }
467 + }
468 +
469 + public var _favorite_couponsets: [String] {
470 + get { return self.favorite_couponsets ?? [] }
471 + set(newValue) { self.favorite_couponsets = newValue }
472 + }
473 +
474 + public var _user_id: String {
475 + get { return self.user_id ?? "" }
476 + set(newValue) { self.user_id = newValue }
477 + }
478 +
479 + public var _is_eligible: Bool {
480 + get { return self.is_eligible ?? false }
481 + set(newValue) { self.is_eligible = newValue }
482 + }
483 +
484 + public var _questionnaire: [String: Any] {
485 + get { return self.questionnaire ?? [String: Any]() }
486 + set(newValue) { self.questionnaire = newValue }
487 + }
488 +
489 + public var _user_answers: [QuestionnaireAnswerModel] {
490 + get { return self.user_answers ?? [] }
491 + set(newValue) { self.user_answers = newValue }
492 + }
493 +
494 + public var _questionnaire_answers: [QuestionnaireAnswerModel] {
495 + get { return self.questionnaire_answers ?? [] }
496 + set(newValue) { self.questionnaire_answers = newValue }
497 + }
498 +
499 + // MARK: - Enhanced profile_metadata Public Accessors
500 + public var _username: String {
501 + get { return self.username ?? "" }
502 + set(newValue) { self.username = newValue }
503 + }
504 +
505 + public var _contract_accounts: [String] {
506 + get { return self.contract_accounts ?? [] }
507 + set(newValue) { self.contract_accounts = newValue }
508 + }
509 +
510 + public var _master_id: String {
511 + get { return self.master_id ?? "" }
512 + set(newValue) { self.master_id = newValue }
513 + }
514 +
515 + public var _questionnaire_v2: [String: Any] {
516 + get { return self.questionnaire_v2 ?? [String: Any]() }
517 + set(newValue) { self.questionnaire_v2 = newValue }
518 + }
519 +
520 + public var _answered_count: Int {
521 + get { return self.answered_count ?? 0 }
522 + set(newValue) { self.answered_count = newValue }
523 + }
524 +
367 // MARK: - Computed Properties 525 // MARK: - Computed Properties
368 public var fullName: String { 526 public var fullName: String {
369 let first = firstname ?? "" 527 let first = firstname ?? ""
......
1 +//
2 +// QuestionnaireAnswerModel.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Warply on 04/09/2025.
6 +//
7 +
8 +import Foundation
9 +
10 +@objc public class QuestionnaireAnswerModel: NSObject {
11 +
12 + // MARK: - Private Properties
13 + private var _question_id: String?
14 + private var _question_text: String?
15 + private var _answer: Any? // Can be String or [String]
16 + private var _answer_id: String?
17 + private var _answer_text: String?
18 +
19 + // MARK: - Public Accessors
20 + @objc public var question_id: String {
21 + get { return _question_id ?? "" }
22 + set { _question_id = newValue }
23 + }
24 +
25 + @objc public var question_text: String {
26 + get { return _question_text ?? "" }
27 + set { _question_text = newValue }
28 + }
29 +
30 + @objc public var answer_id: String {
31 + get { return _answer_id ?? "" }
32 + set { _answer_id = newValue }
33 + }
34 +
35 + @objc public var answer_text: String {
36 + get { return _answer_text ?? "" }
37 + set { _answer_text = newValue }
38 + }
39 +
40 + // MARK: - Answer Handling (Mixed Types)
41 + @objc public var answerAsString: String {
42 + if let stringAnswer = _answer as? String {
43 + return stringAnswer
44 + } else if let arrayAnswer = _answer as? [String] {
45 + return arrayAnswer.joined(separator: ", ")
46 + }
47 + return ""
48 + }
49 +
50 + @objc public var answerAsArray: [String] {
51 + if let arrayAnswer = _answer as? [String] {
52 + return arrayAnswer
53 + } else if let stringAnswer = _answer as? String {
54 + return [stringAnswer]
55 + }
56 + return []
57 + }
58 +
59 + @objc public var rawAnswer: Any? {
60 + return _answer
61 + }
62 +
63 + // MARK: - Initializers
64 + @objc public override init() {
65 + super.init()
66 + }
67 +
68 + @objc public init(dictionary: [String: Any]) {
69 + super.init()
70 +
71 + if let questionId = dictionary["question_id"] as? String {
72 + self._question_id = questionId
73 + }
74 +
75 + if let questionText = dictionary["question_text"] as? String {
76 + self._question_text = questionText
77 + }
78 +
79 + if let answerId = dictionary["answer_id"] as? String {
80 + self._answer_id = answerId
81 + }
82 +
83 + if let answerText = dictionary["answer_text"] as? String {
84 + self._answer_text = answerText
85 + }
86 +
87 + // Handle mixed answer types (String or [String])
88 + if let answer = dictionary["answer"] {
89 + self._answer = answer
90 + }
91 + }
92 +
93 + // MARK: - Utility Methods
94 + @objc public func toDictionary() -> [String: Any] {
95 + var dict: [String: Any] = [:]
96 +
97 + if let questionId = _question_id {
98 + dict["question_id"] = questionId
99 + }
100 +
101 + if let questionText = _question_text {
102 + dict["question_text"] = questionText
103 + }
104 +
105 + if let answerId = _answer_id {
106 + dict["answer_id"] = answerId
107 + }
108 +
109 + if let answerText = _answer_text {
110 + dict["answer_text"] = answerText
111 + }
112 +
113 + if let answer = _answer {
114 + dict["answer"] = answer
115 + }
116 +
117 + return dict
118 + }
119 +
120 + @objc public var description: String {
121 + return "QuestionnaireAnswerModel(question_id: \(question_id), question_text: \(question_text), answer: \(answerAsString), answer_id: \(answer_id), answer_text: \(answer_text))"
122 + }
123 +}