module Cachix.Types.NarInfoCreate
( NarInfoCreate (..),
NarInfoInvalid,
isNarInfoCreateValid
)
where
import Control.Exception (Exception)
import Data.Aeson
( FromJSON,
ToJSON
)
import Data.Swagger
import Data.Text (Text)
import GHC.Generics (Generic)
data NarInfoCreate
= NarInfoCreate
{ cStoreHash :: Text,
cStoreSuffix :: Text,
cNarHash :: Text,
cNarSize :: Integer,
cFileHash :: Text,
cFileSize :: Integer,
cReferences :: [Text],
cDeriver :: Text,
cSig :: Text
}
deriving (Generic, Show, FromJSON, ToJSON, ToSchema)
data NarInfoInvalid
= NarSizeIsZero
deriving (Show, Exception)
isNarInfoCreateValid :: NarInfoCreate -> Either NarInfoInvalid ()
isNarInfoCreateValid nic
| cNarSize nic == 0 = Left NarSizeIsZero
| otherwise = Right ()