+-- | XML Representation of a \<Detailed_Weather\>, which just contains
+-- a bunch iof \<DW_Listing\>s. There is no associated database type
+-- since these don't really contain any information.
+--
+data WeatherDetailedWeatherXml =
+ WeatherDetailedWeatherXml {
+ xml_detailed_listings :: [WeatherDetailedWeatherListingXml] }
+ deriving (Eq, Show)
+
+
+-- * WeatherDetailedWeatherXml
+
+-- | XML Representation of a \<DW_Listing\>. The sport and sport code
+-- come as attributes, but then these just contain a bunch of
+-- \<Item\>s. There is no associated database type since these don't
+-- contain much information. The sport we already know from the
+-- \<message\>, while the sport code is ignored since it's already
+-- present in each \<Item\>s.
+--
+data WeatherDetailedWeatherListingXml =
+ WeatherDetailedWeatherListingXml
+ String -- xml_dtl_listing_sport, unused
+ String -- xml_dtl_listing_sport_code, unused
+ [WeatherDetailedWeatherListingItemXml] -- xml_items
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | Accessor for the third field of WeatherDetailedWeatherListingXml.
+-- We don't use field names to avoid the unused field warnings that
+-- we'd otherwise get for the first two fields.
+--
+xml_items :: WeatherDetailedWeatherListingXml
+ -> [WeatherDetailedWeatherListingItemXml]
+xml_items (WeatherDetailedWeatherListingXml _ _ items) = items
+
+
+-- | For 'H.convert'.
+--
+instance H.HVector WeatherDetailedWeatherListingXml
+
+
+-- * WeatherDetailedWeatherListingItem / WeatherDetailedWeatherListingItemXml
+
+-- | Database representation of a detailed weather item. The away/home
+-- teams don't use the representation in "TSN.Team" because all
+-- we're given is a name, and a team id is required for "TSN.Team".
+--
+-- We also drop the sport name, because it's given in the parent
+-- 'Weather'.
+--
+-- The leading underscores prevent unused field warnings.
+--
+data WeatherDetailedWeatherListingItem =
+ WeatherDetailedWeatherListingItem {
+ _db_dtl_weather_id :: DefaultKey Weather, -- ^ Avoid name collision by
+ -- using \"dtl\" prefix.
+ _db_sport_code :: String,
+ _db_game_id :: Int,
+ _db_dtl_game_date :: UTCTime, -- ^ Avoid name clash with \"dtl\" prefix
+ _db_away_team :: String,
+ _db_home_team :: String,
+ _db_weather_type :: Int,
+ _db_description :: Maybe String,
+ _db_temp_adjust :: Maybe String,
+ _db_temperature :: Int }
+ deriving ( GHC.Generic )
+
+-- | For 'H.cons' and 'H.convert'.
+--
+instance H.HVector WeatherDetailedWeatherListingItem
+
+
+-- | XML representation of a detailed weather item. Same as the
+-- database representation, only without the foreign key and the
+-- sport name that comes from the containing listing.
+--
+-- The leading underscores prevent unused field warnings.
+--
+data WeatherDetailedWeatherListingItemXml =
+ WeatherDetailedWeatherListingItemXml {
+ _xml_sport_code :: String,
+ _xml_game_id :: Int,
+ _xml_dtl_game_date :: UTCTime,
+ _xml_away_team :: String,
+ _xml_home_team :: String,
+ _xml_weather_type :: Int,
+ _xml_description :: Maybe String,
+ _xml_temp_adjust :: Maybe String,
+ _xml_temperature :: Int }
+ deriving (Eq, GHC.Generic, Show)
+
+
+-- | For 'H.convert'.
+--
+instance H.HVector WeatherDetailedWeatherListingItemXml
+
+instance ToDb WeatherDetailedWeatherListingItemXml where
+ -- | Our database analogue is a 'WeatherDetailedWeatherListingItem'.
+ type Db WeatherDetailedWeatherListingItemXml =
+ WeatherDetailedWeatherListingItem
+
+instance Child WeatherDetailedWeatherListingItemXml where
+ -- | We skip two levels of containers and say that the items belong
+ -- to the top-level 'Weather'.
+ type Parent WeatherDetailedWeatherListingItemXml = Weather
+
+instance FromXmlFk WeatherDetailedWeatherListingItemXml where
+ -- | To convert from the XML to database representation, we simply
+ -- add the foreign key (to Weather) and copy the rest of the fields.
+ from_xml_fk = H.cons
+
+-- | This allows us to insert the XML representation directly without
+-- having to do the manual XML -\> DB conversion.
+--
+instance XmlImportFk WeatherDetailedWeatherListingItemXml
+
+-- * Weather/Message
+
+-- | The database representation of a weather message. We don't
+-- contain the forecasts or the detailed weather since those are
+-- foreigned-keyed to us.