|
| 1 | +package io.intrepid.contest.models |
| 2 | + |
| 3 | +import android.os.Parcel |
| 4 | +import com.google.gson.annotations.SerializedName |
| 5 | +import timber.log.Timber |
| 6 | +import java.util.* |
| 7 | + |
| 8 | +open class Contest { |
| 9 | + @SerializedName("id") |
| 10 | + var id: UUID? = null |
| 11 | + var creatorId: UUID? = null |
| 12 | + @SerializedName("created_at") |
| 13 | + var creationDate: Date? = null |
| 14 | + @SerializedName("updated_at") |
| 15 | + var lastUpdatedDate: Date? = null |
| 16 | + @SerializedName("ended_at") |
| 17 | + var endedDate: Date? = null |
| 18 | + set(value) { |
| 19 | + this.endedDate = endedDate |
| 20 | + } |
| 21 | + var title: String? = null |
| 22 | + var description: String? = null |
| 23 | + @SerializedName("scoring_categories") |
| 24 | + var categories: List<Category>? = null |
| 25 | + var entries: List<Entry>? = null |
| 26 | + var submissionsClosedAt: Date? = null |
| 27 | + var participationType: ParticipationType? = null |
| 28 | + |
| 29 | + init { |
| 30 | + id = UUID.randomUUID() |
| 31 | + categories = ArrayList<Category>() |
| 32 | + } |
| 33 | + |
| 34 | + override fun toString(): String { |
| 35 | + return title + "/n" + |
| 36 | + description + "/n" + |
| 37 | + id + "/n" + |
| 38 | + creatorId + " " + creationDate + |
| 39 | + " /n size of categories was " + categories!!.size + |
| 40 | + "categories " + categories + |
| 41 | + " /n Last updated " + lastUpdatedDate + |
| 42 | + " /n Ended Data " + endedDate |
| 43 | + } |
| 44 | + |
| 45 | + class Builder { |
| 46 | + var categories: List<Category> = ArrayList() |
| 47 | + var title: String? = null |
| 48 | + var description: String? = null |
| 49 | + internal var contestId: UUID? = null |
| 50 | + internal var creatorId: UUID? = null |
| 51 | + internal var creationDate: Date? = null |
| 52 | + internal var lastUpdatedDate: Date? = null |
| 53 | + internal var endedDate: Date? = null |
| 54 | + |
| 55 | + constructor() : this(UUID(UUID_MIN_LIMIT.toLong(), UUID_MAX_LIMIT.toLong())) {} |
| 56 | + |
| 57 | + internal constructor(creatorId: UUID) { |
| 58 | + this.creatorId = creatorId |
| 59 | + this.contestId = UUID(UUID_MIN_LIMIT.toLong(), UUID_MAX_LIMIT.toLong()) |
| 60 | + } |
| 61 | + |
| 62 | + protected constructor(`in`: Parcel) { |
| 63 | + title = `in`.readString() |
| 64 | + description = `in`.readString() |
| 65 | + } |
| 66 | + |
| 67 | + fun setTitle(title: String): Builder { |
| 68 | + this.title = title |
| 69 | + return this |
| 70 | + } |
| 71 | + |
| 72 | + fun setDescription(description: String): Builder { |
| 73 | + this.description = description |
| 74 | + return this |
| 75 | + } |
| 76 | + |
| 77 | + fun build(): Contest { |
| 78 | + if (creationDate == null) { |
| 79 | + creationDate = Date() |
| 80 | + } |
| 81 | + if (lastUpdatedDate == null) { |
| 82 | + lastUpdatedDate = Date() |
| 83 | + } |
| 84 | + Timber.d(this.toString()) |
| 85 | + val contest = Contest() |
| 86 | + contest.id = this.contestId |
| 87 | + contest.creatorId = this.creatorId |
| 88 | + contest.lastUpdatedDate = Date() |
| 89 | + contest.creationDate = this.creationDate |
| 90 | + contest.endedDate = this.endedDate |
| 91 | + contest.title = this.title |
| 92 | + contest.description = this.description |
| 93 | + contest.categories = this.categories |
| 94 | + return contest |
| 95 | + } |
| 96 | + |
| 97 | + companion object { |
| 98 | + internal val UUID_MIN_LIMIT = 0 |
| 99 | + internal val UUID_MAX_LIMIT = Integer.MAX_VALUE |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments