module Cachix.Types.PinCreate where

import Data.Aeson (FromJSON, ToJSON)
import Data.Swagger (ToSchema (..), defaultSchemaOptions, genericDeclareNamedSchemaUnrestricted)
import Protolude

data Keep = Days Int | Revisions Int | Forever
  deriving (Int -> Keep -> ShowS
[Keep] -> ShowS
Keep -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Keep] -> ShowS
$cshowList :: [Keep] -> ShowS
show :: Keep -> String
$cshow :: Keep -> String
showsPrec :: Int -> Keep -> ShowS
$cshowsPrec :: Int -> Keep -> ShowS
Show, Keep -> Keep -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Keep -> Keep -> Bool
$c/= :: Keep -> Keep -> Bool
== :: Keep -> Keep -> Bool
$c== :: Keep -> Keep -> Bool
Eq, forall x. Rep Keep x -> Keep
forall x. Keep -> Rep Keep x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Keep x -> Keep
$cfrom :: forall x. Keep -> Rep Keep x
Generic, [Keep] -> Encoding
[Keep] -> Value
Keep -> Encoding
Keep -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Keep] -> Encoding
$ctoEncodingList :: [Keep] -> Encoding
toJSONList :: [Keep] -> Value
$ctoJSONList :: [Keep] -> Value
toEncoding :: Keep -> Encoding
$ctoEncoding :: Keep -> Encoding
toJSON :: Keep -> Value
$ctoJSON :: Keep -> Value
ToJSON, Value -> Parser [Keep]
Value -> Parser Keep
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Keep]
$cparseJSONList :: Value -> Parser [Keep]
parseJSON :: Value -> Parser Keep
$cparseJSON :: Value -> Parser Keep
FromJSON)

-- to support Keep with data constructor with arguments
instance ToSchema Keep where
  declareNamedSchema :: Proxy Keep -> Declare (Definitions Schema) NamedSchema
declareNamedSchema = forall a.
(Generic a, GToSchema (Rep a)) =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchemaUnrestricted SchemaOptions
defaultSchemaOptions

data PinCreate = PinCreate
  { PinCreate -> Text
name :: Text,
    PinCreate -> Text
storePath :: Text,
    PinCreate -> [Text]
artifacts :: [Text],
    PinCreate -> Maybe Keep
keep :: Maybe Keep
  }
  deriving (Int -> PinCreate -> ShowS
[PinCreate] -> ShowS
PinCreate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PinCreate] -> ShowS
$cshowList :: [PinCreate] -> ShowS
show :: PinCreate -> String
$cshow :: PinCreate -> String
showsPrec :: Int -> PinCreate -> ShowS
$cshowsPrec :: Int -> PinCreate -> ShowS
Show, PinCreate -> PinCreate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PinCreate -> PinCreate -> Bool
$c/= :: PinCreate -> PinCreate -> Bool
== :: PinCreate -> PinCreate -> Bool
$c== :: PinCreate -> PinCreate -> Bool
Eq, forall x. Rep PinCreate x -> PinCreate
forall x. PinCreate -> Rep PinCreate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PinCreate x -> PinCreate
$cfrom :: forall x. PinCreate -> Rep PinCreate x
Generic, [PinCreate] -> Encoding
[PinCreate] -> Value
PinCreate -> Encoding
PinCreate -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PinCreate] -> Encoding
$ctoEncodingList :: [PinCreate] -> Encoding
toJSONList :: [PinCreate] -> Value
$ctoJSONList :: [PinCreate] -> Value
toEncoding :: PinCreate -> Encoding
$ctoEncoding :: PinCreate -> Encoding
toJSON :: PinCreate -> Value
$ctoJSON :: PinCreate -> Value
ToJSON, Value -> Parser [PinCreate]
Value -> Parser PinCreate
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PinCreate]
$cparseJSONList :: Value -> Parser [PinCreate]
parseJSON :: Value -> Parser PinCreate
$cparseJSON :: Value -> Parser PinCreate
FromJSON, Proxy PinCreate -> Declare (Definitions Schema) NamedSchema
forall a.
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
declareNamedSchema :: Proxy PinCreate -> Declare (Definitions Schema) NamedSchema
$cdeclareNamedSchema :: Proxy PinCreate -> Declare (Definitions Schema) NamedSchema
ToSchema)