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

module WikiMusic.Model.Artwork
  ( Artwork (..),
    parseArtworkRows,
  )
where

import Data.Aeson
import Data.OpenApi
import Relude
import Data.Time
import Data.UUID
import Optics

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

makeFieldLabelsNoPrefix ''Artwork

parseArtworkRows :: (JoinKinds k1 l k2, Is k2 A_Getter, LabelOptic "identifier" l u v a1 a1, LabelOptic "artwork" k1 b b u v) => (a2 -> b) -> [a2] -> [(a1, b)]
parseArtworkRows :: 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 "artwork" k1 b b u v) =>
(a2 -> b) -> [a2] -> [(a1, b)]
parseArtworkRows 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
#artwork 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)