-
Notifications
You must be signed in to change notification settings - Fork 1
/
BetItem.swift
120 lines (98 loc) · 3.36 KB
/
BetItem.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// BetItem.swift
// WagerApp
//
// Created by Tyler Kaye, Michael Swart, Richard Bush, and William Chance on 4/2/17.
//
import Foundation
import Firebase
struct BetItem {
let ref: FIRDatabaseReference?
let key: String
var name: String
var description: String
let challenger_uid: String //this might change
let challenger_name: String
var challengee_uid: String //This might change
var challengee_name: String
var amount: Float
var category: String
let date_opened: Double
let date_closed: Double
var accepted: Bool
var completed: Bool
var confirmed: Bool
var paid: Bool
var winner: Bool //True means that challenger won
var arbitration: Bool
init(key: String = "", name: String, description: String, challenger_uid: String,
challenger_name: String, date_opened: Double, date_closed: Double, category: String, amount: Float, challengee_uid: String = "", challengee_name: String = "", accepted: Bool = false, completed: Bool = false, confirmed: Bool = false, winner: Bool = true, arbitration: Bool = false) {
self.ref = nil
self.key = key
self.name = name
self.description = description
self.challenger_uid = challenger_uid
self.challenger_name = challenger_name
self.challengee_uid = challengee_uid
self.challengee_name = challengee_name
self.amount = amount
self.category = category
self.date_opened = date_opened
self.date_closed = date_closed
self.accepted = accepted
self.completed = completed
self.confirmed = confirmed
self.paid = false
self.winner = winner
self.arbitration = arbitration
}
init(snapshot: FIRDataSnapshot) {
ref = snapshot.ref
key = snapshot.key
let snapshotValue = snapshot.value as! [String: AnyObject]
name = snapshotValue["name"] as! String
description = snapshotValue["description"] as! String
challenger_uid = snapshotValue["challenger_uid"] as! String
challenger_name = snapshotValue["challenger_name"] as! String
challengee_uid = snapshotValue["challengee_uid"] as! String
challengee_name = snapshotValue["challengee_name"] as! String
amount = snapshotValue["amount"] as! Float
category = snapshotValue["category"] as! String
date_opened = snapshotValue["date_opened"] as! Double
date_closed = snapshotValue["date_closed"] as! Double
accepted = snapshotValue["accepted"] as! Bool
completed = snapshotValue["completed"] as! Bool
confirmed = snapshotValue["confirmed"] as! Bool
paid = snapshotValue["paid"] as! Bool
winner = snapshotValue["winner"] as! Bool
arbitration = snapshotValue["arbitration"] as! Bool
}
func isEqual(_ object: Any?) -> Bool {
if let other = object as? BetItem {
return self.key == other.key
}
else {
return false
}
}
func toAnyObject() -> Any {
return [
"name": name,
"description": description,
"challenger_uid": challenger_uid,
"challenger_name": challenger_name,
"challengee_uid": challengee_uid,
"challengee_name": challengee_name,
"amount": amount,
"category": category,
"date_opened": date_opened,
"date_closed": date_closed,
"accepted": accepted,
"completed": completed,
"confirmed": confirmed,
"paid": paid,
"winner": winner,
"arbitration": arbitration
]
}
}