module Model exposing
    (
      Model
    , TrackState(..)
    , DragState(..)
    , empty
    , isMarkActive
    , marks
    )
import TileMap exposing (ZoomLevel(..), Coord, toCoord)
import Point exposing (Point)
import Pos exposing (Pos)

type DragState =
    DragMap (Int, Int) Coord
  | DragGraph (Int, Int) Float
  | DragLeftMark (Int, Int) Float
  | DragRightMark (Int, Int) Float

type TrackState = Empty | Loading | Failure String | Present (List Point)

type alias Model =
    { centre: Coord
    , zoom: ZoomLevel
    , drag: Maybe DragState
    , startTime : Float
    , duration : Float
    , leftMark : Float
    , rightMark : Float
    , track: TrackState }

empty = Model
        (toCoord (Pos 0 0 Nothing))
        (ZoomLevel 0)
        Nothing
        0 0
        0 0
        Loading

isMarkActive model =
    model.leftMark > model.startTime ||
        model.rightMark < (model.startTime + model.duration)

marks model =
    if isMarkActive model
    then Just (model.leftMark, model.rightMark)
    else Nothing
