package com.peacock.fantafone


/**
 * Created by fabrizio on 27/12/16.

 */

class Drivers {

    var level: Int = 0

    var points: Int = 0

    var positionD: Int = 0

    var nameD: String? = null

    private var fastLap = false
    private var bestQ = false
    private var beatTM = false
    private var bRetired = false




    fun setName(names: String) {
        this.nameD = names
    }

    fun getName(): String {
        if (nameD != null)
            return this.nameD!!
        else
            return ""
    }

    fun setbRetired(r: Boolean) {
        this.bRetired = r
    }

    fun setPosition(pos: Int) {
        positionD = pos
    }

    fun setFastLap(f: Boolean) {
        this.fastLap = f
    }

    fun setBestQ(q: Boolean) {
        this.bestQ = q
    }

    fun setBeatTM(b: Boolean) {
        this.beatTM = b
    }

    val calcPoints: Int
        get() {
            if (level == Companion.L_LOW) {
                if (positionD == 1) {
                    points = 25
                } else if (positionD in 2..3) {
                    points = 20
                } else if (positionD in 4..6) {
                    points = 12
                } else if (positionD in 7..10) {
                    points = 8
                } else if (positionD in 11..16) {
                    points = 3
                } else if (positionD in 17..18) {
                    points = 1
                } else if (positionD in 19..20) {
                    points = 0
                }
                if (beatTM) points += 5
                if (bRetired) points = 0
                if (fastLap) points += 4
                if (bestQ) points += 1

            } else if (level == L_MED) {
                if (positionD == 1) {
                    points = 12
                } else if (positionD in 2..3) {
                    points = 8
                } else if (positionD in 4..6) {
                    points = 5
                } else if (positionD in 7..10) {
                    points = 3
                } else if (positionD in 11..16) {
                    points = 1
                } else if (positionD in 17..18) {
                    points = -2
                } else if (positionD in 19..20) {
                    points = -4
                }
                if (beatTM) points += 5
                if (bRetired) points = 0
                if (fastLap) points += 2
                if (bestQ) points += 2
            } else if (level == Companion.L_TOP) {
                if (positionD == 1) {
                    points = 5
                } else if (positionD in 2..3) {
                    points = 3
                } else if (positionD in 4..6) {
                    points = 1
                } else if (positionD in 7..10) {
                    points = -1
                } else if (positionD in 11..16) {
                    points = -4
                } else if (positionD in 17..18) {
                    points = -6
                } else if (positionD in 19..20) {
                    points = -8
                }
                if (beatTM) points += 5
                if (bRetired) points = 0
                if (fastLap) points += 1
                if (bestQ) points += 1
            }
            return this.points
        }

    fun getPointsString(ddd: String): String {
        var build = ddd
        val pos: String
        val faL: String
        val beQ: String
        val rit: String
        val bet: String
        if (fastLap) faL = "1" else faL = "0"
        if (bestQ) beQ = "1" else beQ = "0"
        if (bRetired) rit = "1" else rit = "0"
        if (beatTM) bet = "1" else bet = "0"
        if (positionD < 10)
            pos = "00" + positionD.toString()
        else
            pos = "0" + positionD.toString()

        build = build + ":" + bet + pos + "000" + faL + "000" + beQ + "000" + rit

        return build
    }

    companion object {
        val L_LOW = 0
        val L_MED = 1
        val L_TOP = 2
    }



}
