|
|
|
@ -20,7 +20,19 @@ public class BetDetail: ObservableObject {
|
|
|
|
|
public private(set) var participations: [Participation]
|
|
|
|
|
|
|
|
|
|
/// The final answer selected for the bet, if available.
|
|
|
|
|
public private(set) var finalAnswer: String?
|
|
|
|
|
public private(set) var wonParticipation: Participation?
|
|
|
|
|
public private(set) var userParticipation: Participation?
|
|
|
|
|
|
|
|
|
|
public var odds: Float? {
|
|
|
|
|
guard let wonParticipation = self.wonParticipation else {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if let matchingAnswer = self.answers.first(where: { $0.response == wonParticipation.answer }) {
|
|
|
|
|
return matchingAnswer.odds
|
|
|
|
|
} else {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Custom Constructor
|
|
|
|
|
///
|
|
|
|
@ -29,18 +41,19 @@ public class BetDetail: ObservableObject {
|
|
|
|
|
/// - answers: Details about the answers available for the bet.
|
|
|
|
|
/// - participations: List of user participations in the bet.
|
|
|
|
|
/// - finalAnswer: The final answer selected for the bet, if available.
|
|
|
|
|
public init(bet: Bet, answers: [AnswerDetail], participations: [Participation], finalAnswer: String? = nil) {
|
|
|
|
|
public init(bet: Bet, answers: [AnswerDetail], participations: [Participation], wonParticipation: Participation? = nil, userParticipation: Participation? = nil) {
|
|
|
|
|
self.bet = bet
|
|
|
|
|
self.answers = answers
|
|
|
|
|
self.participations = participations
|
|
|
|
|
self.finalAnswer = finalAnswer
|
|
|
|
|
self.wonParticipation = wonParticipation
|
|
|
|
|
self.userParticipation = userParticipation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Updates the final answer selected for the bet.
|
|
|
|
|
///
|
|
|
|
|
/// - Parameter newFinalAnswer: The new final answer for the bet.
|
|
|
|
|
public func updateFinalAnswer(newFinalAnswer: String) {
|
|
|
|
|
self.finalAnswer = newFinalAnswer
|
|
|
|
|
public func updateFinalAnswer(wonParticipation: Participation) {
|
|
|
|
|
self.wonParticipation = wonParticipation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Adds a new user participation to the list of participations for the bet.
|
|
|
|
|