module TD.Data.StoryAreaPosition
  ( StoryAreaPosition(..)    
  , defaultStoryAreaPosition 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data StoryAreaPosition
  = StoryAreaPosition -- ^ Describes position of a clickable rectangle area on a story media
    { StoryAreaPosition -> Maybe Double
x_percentage             :: Maybe Double -- ^ The abscissa of the rectangle's center, as a percentage of the media width
    , StoryAreaPosition -> Maybe Double
y_percentage             :: Maybe Double -- ^ The ordinate of the rectangle's center, as a percentage of the media height
    , StoryAreaPosition -> Maybe Double
width_percentage         :: Maybe Double -- ^ The width of the rectangle, as a percentage of the media width
    , StoryAreaPosition -> Maybe Double
height_percentage        :: Maybe Double -- ^ The height of the rectangle, as a percentage of the media height
    , StoryAreaPosition -> Maybe Double
rotation_angle           :: Maybe Double -- ^ Clockwise rotation angle of the rectangle, in degrees; 0-360
    , StoryAreaPosition -> Maybe Double
corner_radius_percentage :: Maybe Double -- ^ The radius of the rectangle corner rounding, as a percentage of the media width
    }
  deriving (StoryAreaPosition -> StoryAreaPosition -> Bool
(StoryAreaPosition -> StoryAreaPosition -> Bool)
-> (StoryAreaPosition -> StoryAreaPosition -> Bool)
-> Eq StoryAreaPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryAreaPosition -> StoryAreaPosition -> Bool
== :: StoryAreaPosition -> StoryAreaPosition -> Bool
$c/= :: StoryAreaPosition -> StoryAreaPosition -> Bool
/= :: StoryAreaPosition -> StoryAreaPosition -> Bool
Eq, Int -> StoryAreaPosition -> ShowS
[StoryAreaPosition] -> ShowS
StoryAreaPosition -> String
(Int -> StoryAreaPosition -> ShowS)
-> (StoryAreaPosition -> String)
-> ([StoryAreaPosition] -> ShowS)
-> Show StoryAreaPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryAreaPosition -> ShowS
showsPrec :: Int -> StoryAreaPosition -> ShowS
$cshow :: StoryAreaPosition -> String
show :: StoryAreaPosition -> String
$cshowList :: [StoryAreaPosition] -> ShowS
showList :: [StoryAreaPosition] -> ShowS
Show)

instance I.ShortShow StoryAreaPosition where
  shortShow :: StoryAreaPosition -> String
shortShow StoryAreaPosition
    { x_percentage :: StoryAreaPosition -> Maybe Double
x_percentage             = Maybe Double
x_percentage_
    , y_percentage :: StoryAreaPosition -> Maybe Double
y_percentage             = Maybe Double
y_percentage_
    , width_percentage :: StoryAreaPosition -> Maybe Double
width_percentage         = Maybe Double
width_percentage_
    , height_percentage :: StoryAreaPosition -> Maybe Double
height_percentage        = Maybe Double
height_percentage_
    , rotation_angle :: StoryAreaPosition -> Maybe Double
rotation_angle           = Maybe Double
rotation_angle_
    , corner_radius_percentage :: StoryAreaPosition -> Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
    }
      = String
"StoryAreaPosition"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"x_percentage"             String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
x_percentage_
        , String
"y_percentage"             String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
y_percentage_
        , String
"width_percentage"         String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
width_percentage_
        , String
"height_percentage"        String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
height_percentage_
        , String
"rotation_angle"           String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
rotation_angle_
        , String
"corner_radius_percentage" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
corner_radius_percentage_
        ]

instance AT.FromJSON StoryAreaPosition where
  parseJSON :: Value -> Parser StoryAreaPosition
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"storyAreaPosition" -> Value -> Parser StoryAreaPosition
parseStoryAreaPosition Value
v
      String
_                   -> Parser StoryAreaPosition
forall a. Monoid a => a
mempty
    
    where
      parseStoryAreaPosition :: A.Value -> AT.Parser StoryAreaPosition
      parseStoryAreaPosition :: Value -> Parser StoryAreaPosition
parseStoryAreaPosition = String
-> (Object -> Parser StoryAreaPosition)
-> Value
-> Parser StoryAreaPosition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaPosition" ((Object -> Parser StoryAreaPosition)
 -> Value -> Parser StoryAreaPosition)
-> (Object -> Parser StoryAreaPosition)
-> Value
-> Parser StoryAreaPosition
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Double
x_percentage_             <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"x_percentage"
        Maybe Double
y_percentage_             <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"y_percentage"
        Maybe Double
width_percentage_         <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"width_percentage"
        Maybe Double
height_percentage_        <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"height_percentage"
        Maybe Double
rotation_angle_           <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"rotation_angle"
        Maybe Double
corner_radius_percentage_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"corner_radius_percentage"
        StoryAreaPosition -> Parser StoryAreaPosition
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaPosition -> Parser StoryAreaPosition)
-> StoryAreaPosition -> Parser StoryAreaPosition
forall a b. (a -> b) -> a -> b
$ StoryAreaPosition
          { x_percentage :: Maybe Double
x_percentage             = Maybe Double
x_percentage_
          , y_percentage :: Maybe Double
y_percentage             = Maybe Double
y_percentage_
          , width_percentage :: Maybe Double
width_percentage         = Maybe Double
width_percentage_
          , height_percentage :: Maybe Double
height_percentage        = Maybe Double
height_percentage_
          , rotation_angle :: Maybe Double
rotation_angle           = Maybe Double
rotation_angle_
          , corner_radius_percentage :: Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
          }
  parseJSON Value
_ = Parser StoryAreaPosition
forall a. Monoid a => a
mempty

instance AT.ToJSON StoryAreaPosition where
  toJSON :: StoryAreaPosition -> Value
toJSON StoryAreaPosition
    { x_percentage :: StoryAreaPosition -> Maybe Double
x_percentage             = Maybe Double
x_percentage_
    , y_percentage :: StoryAreaPosition -> Maybe Double
y_percentage             = Maybe Double
y_percentage_
    , width_percentage :: StoryAreaPosition -> Maybe Double
width_percentage         = Maybe Double
width_percentage_
    , height_percentage :: StoryAreaPosition -> Maybe Double
height_percentage        = Maybe Double
height_percentage_
    , rotation_angle :: StoryAreaPosition -> Maybe Double
rotation_angle           = Maybe Double
rotation_angle_
    , corner_radius_percentage :: StoryAreaPosition -> Maybe Double
corner_radius_percentage = Maybe Double
corner_radius_percentage_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"                    Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"storyAreaPosition"
        , Key
"x_percentage"             Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
x_percentage_
        , Key
"y_percentage"             Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
y_percentage_
        , Key
"width_percentage"         Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
width_percentage_
        , Key
"height_percentage"        Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
height_percentage_
        , Key
"rotation_angle"           Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
rotation_angle_
        , Key
"corner_radius_percentage" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
corner_radius_percentage_
        ]

defaultStoryAreaPosition :: StoryAreaPosition
defaultStoryAreaPosition :: StoryAreaPosition
defaultStoryAreaPosition =
  StoryAreaPosition
    { x_percentage :: Maybe Double
x_percentage             = Maybe Double
forall a. Maybe a
Nothing
    , y_percentage :: Maybe Double
y_percentage             = Maybe Double
forall a. Maybe a
Nothing
    , width_percentage :: Maybe Double
width_percentage         = Maybe Double
forall a. Maybe a
Nothing
    , height_percentage :: Maybe Double
height_percentage        = Maybe Double
forall a. Maybe a
Nothing
    , rotation_angle :: Maybe Double
rotation_angle           = Maybe Double
forall a. Maybe a
Nothing
    , corner_radius_percentage :: Maybe Double
corner_radius_percentage = Maybe Double
forall a. Maybe a
Nothing
    }