{-# LANGUAGE NoImplicitPrelude #-}

module Panda.Model.Video where

-- env
import Panda.Helper.Env hiding (title, body, size, path, meta, get, width, height)
import qualified Panda.Config.Global as G
import Panda.Helper.StateHelper

data VideoType = MediaPlayer deriving (Eq, Show, Read)

instance Default VideoType where
  def = MediaPlayer 

data Video = Video
  { uid     :: String -- album/08-06-10
  , preview :: String
  , width  :: Int
  , height :: Int
  , video_type :: VideoType
  }
  deriving (Show, Eq)

instance Resource Video where
  resource_title = uid > spaced_url
  
data VideoData = 
    Link
  | Preview
  | Width
  | Height
  | Type
  deriving (Show)

from_list xs = Video 
  { uid = at Link
  , preview = at' Preview ""
  , width = at' Width "400" .read
  , height = at' Height "300" .read
  , video_type = at' Type "media_player" .camel_case.read
  } .return 
  where
    at x = xs.lookup (x.show_data).fromJust
    at' x d = xs.lookup (x .show_data) .fromMaybe d