module Web.Last.Venue where

import Control.Applicative

import Web.Last.Types
import Web.Last.Request
import qualified Web.Last.Parsing as P
import Text.JSON.Combinators

getEvents :: String -> Last [Event]
getEvents venueId = anonRequest "venue.getevents" [("venue",venueId)] [] pa
    where pa = objOf $ inObj "events" $ llArr "event" P.event

getPastEvents :: String -> Last (Paged Event)
getPastEvents venueId = pagedRequest "venue.getpastevents" [("venue",venueId)] [] pa pno
    where   pa = objOf $ inObj "events" $ llArr "event" P.event
            pno = objOf $ inObj "events" $ P.readInt <$> ll "totalPages" strJS

-- Should really return query as well. Does lastFM ever use the query?
search :: String -> Maybe String -> Last (Paged Venue)
search s country = pagedRequest "venue.search" [("venue",s)] [("country",country)] pa pno
   where   pa = objOf $ inObj "results" $ inObj "venuematches" $ llArr "venue" P.venue
           pno = P.openSearchPages


