module Mpv.Data.OsdLevel where

import Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), withScientific)
import Exon (exon)

data OsdLevel =
  SubtitlesOnly
  |
  UserInteraction
  |
  CurrentTime
  |
  CurrentTimeAndStatus
  deriving stock (OsdLevel -> OsdLevel -> Bool
(OsdLevel -> OsdLevel -> Bool)
-> (OsdLevel -> OsdLevel -> Bool) -> Eq OsdLevel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OsdLevel -> OsdLevel -> Bool
$c/= :: OsdLevel -> OsdLevel -> Bool
== :: OsdLevel -> OsdLevel -> Bool
$c== :: OsdLevel -> OsdLevel -> Bool
Eq, Int -> OsdLevel -> ShowS
[OsdLevel] -> ShowS
OsdLevel -> String
(Int -> OsdLevel -> ShowS)
-> (OsdLevel -> String) -> ([OsdLevel] -> ShowS) -> Show OsdLevel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OsdLevel] -> ShowS
$cshowList :: [OsdLevel] -> ShowS
show :: OsdLevel -> String
$cshow :: OsdLevel -> String
showsPrec :: Int -> OsdLevel -> ShowS
$cshowsPrec :: Int -> OsdLevel -> ShowS
Show)

instance ToJSON OsdLevel where
  toJSON :: OsdLevel -> Value
toJSON =
    forall a. ToJSON a => a -> Value
toJSON @Int (Int -> Value) -> (OsdLevel -> Int) -> OsdLevel -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
      OsdLevel
SubtitlesOnly -> Int
0
      OsdLevel
UserInteraction -> Int
1
      OsdLevel
CurrentTime -> Int
2
      OsdLevel
CurrentTimeAndStatus -> Int
3

instance FromJSON OsdLevel where
  parseJSON :: Value -> Parser OsdLevel
parseJSON =
    String
-> (Scientific -> Parser OsdLevel) -> Value -> Parser OsdLevel
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
withScientific String
"OsdLevel" \case
      Scientific
0 -> OsdLevel -> Parser OsdLevel
forall (f :: * -> *) a. Applicative f => a -> f a
pure OsdLevel
SubtitlesOnly
      Scientific
1 -> OsdLevel -> Parser OsdLevel
forall (f :: * -> *) a. Applicative f => a -> f a
pure OsdLevel
UserInteraction
      Scientific
2 -> OsdLevel -> Parser OsdLevel
forall (f :: * -> *) a. Applicative f => a -> f a
pure OsdLevel
CurrentTime
      Scientific
3 -> OsdLevel -> Parser OsdLevel
forall (f :: * -> *) a. Applicative f => a -> f a
pure OsdLevel
CurrentTimeAndStatus
      Scientific
v -> String -> Parser OsdLevel
forall (m :: * -> *) a. MonadFail m => String -> m a
fail [exon|invalid number for OsdLevel: #{show v}|]