module Model.Round
  ( Round
  , maybeBestRound
  ) where

import List
import Time exposing (Time)

type alias Round =
  { duration : Time
  , score : Int
  }

maybeBestRound : List Round -> Maybe Round
maybeBestRound rounds =
  let orderedRounds =
        rounds
          |> List.sortWith roundOrder
          |> List.reverse
  in  case orderedRounds of
        [] -> Nothing
        best :: _ -> Just best

roundOrder : Round -> Round -> Order
roundOrder round1 round2 =
  if round1.score == round2.score
    then
      compare round2.duration round1.duration
    else
      compare round1.score round2.score