{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}

module WikiMusic.Model.Opinion
  ( Opinion (..),
    parseOpinionRows,
  )
where

import Data.Aeson hiding (Success)
import Data.OpenApi
import Data.Time
import Data.UUID
import Relude
import Optics

data Opinion = Opinion
  { Opinion -> UUID
identifier :: UUID,
    Opinion -> UUID
createdBy :: UUID,
    Opinion -> Bool
isLike :: Bool,
    Opinion -> Bool
isDislike :: Bool,
    Opinion -> UTCTime
createdAt :: UTCTime,
    Opinion -> Maybe UTCTime
lastEditedAt :: Maybe UTCTime
  }
  deriving (Opinion -> Opinion -> Bool
(Opinion -> Opinion -> Bool)
-> (Opinion -> Opinion -> Bool) -> Eq Opinion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Opinion -> Opinion -> Bool
== :: Opinion -> Opinion -> Bool
$c/= :: Opinion -> Opinion -> Bool
/= :: Opinion -> Opinion -> Bool
Eq, Int -> Opinion -> ShowS
[Opinion] -> ShowS
Opinion -> String
(Int -> Opinion -> ShowS)
-> (Opinion -> String) -> ([Opinion] -> ShowS) -> Show Opinion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Opinion -> ShowS
showsPrec :: Int -> Opinion -> ShowS
$cshow :: Opinion -> String
show :: Opinion -> String
$cshowList :: [Opinion] -> ShowS
showList :: [Opinion] -> ShowS
Show, (forall x. Opinion -> Rep Opinion x)
-> (forall x. Rep Opinion x -> Opinion) -> Generic Opinion
forall x. Rep Opinion x -> Opinion
forall x. Opinion -> Rep Opinion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Opinion -> Rep Opinion x
from :: forall x. Opinion -> Rep Opinion x
$cto :: forall x. Rep Opinion x -> Opinion
to :: forall x. Rep Opinion x -> Opinion
Generic, Maybe Opinion
Value -> Parser [Opinion]
Value -> Parser Opinion
(Value -> Parser Opinion)
-> (Value -> Parser [Opinion]) -> Maybe Opinion -> FromJSON Opinion
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Opinion
parseJSON :: Value -> Parser Opinion
$cparseJSONList :: Value -> Parser [Opinion]
parseJSONList :: Value -> Parser [Opinion]
$comittedField :: Maybe Opinion
omittedField :: Maybe Opinion
FromJSON, [Opinion] -> Value
[Opinion] -> Encoding
Opinion -> Bool
Opinion -> Value
Opinion -> Encoding
(Opinion -> Value)
-> (Opinion -> Encoding)
-> ([Opinion] -> Value)
-> ([Opinion] -> Encoding)
-> (Opinion -> Bool)
-> ToJSON Opinion
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Opinion -> Value
toJSON :: Opinion -> Value
$ctoEncoding :: Opinion -> Encoding
toEncoding :: Opinion -> Encoding
$ctoJSONList :: [Opinion] -> Value
toJSONList :: [Opinion] -> Value
$ctoEncodingList :: [Opinion] -> Encoding
toEncodingList :: [Opinion] -> Encoding
$comitField :: Opinion -> Bool
omitField :: Opinion -> Bool
ToJSON, Typeable Opinion
Typeable Opinion =>
(Proxy Opinion -> Declare (Definitions Schema) NamedSchema)
-> ToSchema Opinion
Proxy Opinion -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy Opinion -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy Opinion -> Declare (Definitions Schema) NamedSchema
ToSchema)

makeFieldLabelsNoPrefix ''Opinion

parseOpinionRows :: (JoinKinds k1 l k2, Is k2 A_Getter, LabelOptic "identifier" l u v a1 a1, LabelOptic "opinion" k1 b b u v) => (a2 -> b) -> [a2] -> [(a1, b)]
parseOpinionRows :: forall k1 l k2 u v a1 b a2.
(JoinKinds k1 l k2, Is k2 A_Getter,
 LabelOptic "identifier" l u v a1 a1,
 LabelOptic "opinion" k1 b b u v) =>
(a2 -> b) -> [a2] -> [(a1, b)]
parseOpinionRows a2 -> b
fromRow = (a2 -> (a1, b)) -> [a2] -> [(a1, b)]
forall a b. (a -> b) -> [a] -> [b]
map ((\b
x -> (b
x b -> Optic' k2 NoIx b a1 -> a1
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic k1 NoIx b b u v
#opinion Optic k1 NoIx b b u v
-> Optic l NoIx u v a1 a1 -> Optic' k2 NoIx b a1
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l NoIx u v a1 a1
#identifier, b
x)) (b -> (a1, b)) -> (a2 -> b) -> a2 -> (a1, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a2 -> b
fromRow)