{-# LANGUAGE TemplateHaskell #-}
module Horizon.Spec.Types.PackagesDir (PackagesDir(MkPackagesDir), fromPackagesDir, mkPackagesDir) where

import           Data.Kind                (Type)
import           Dhall                    (FromDhall, ToDhall)
import           Language.Haskell.TH      (Exp, Q)
import           Language.Haskell.TH.Lift (deriveLift, lift)
import           Path                     (Dir, Path, Rel, parseRelDir)
import           Path.Dhall               ()

type PackagesDir :: Type
newtype PackagesDir = MkPackagesDir { PackagesDir -> Path Rel Dir
fromPackagesDir :: Path Rel Dir }
  deriving stock (PackagesDir -> PackagesDir -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackagesDir -> PackagesDir -> Bool
$c/= :: PackagesDir -> PackagesDir -> Bool
== :: PackagesDir -> PackagesDir -> Bool
$c== :: PackagesDir -> PackagesDir -> Bool
Eq, Int -> PackagesDir -> ShowS
[PackagesDir] -> ShowS
PackagesDir -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PackagesDir] -> ShowS
$cshowList :: [PackagesDir] -> ShowS
show :: PackagesDir -> String
$cshow :: PackagesDir -> String
showsPrec :: Int -> PackagesDir -> ShowS
$cshowsPrec :: Int -> PackagesDir -> ShowS
Show)
  deriving newtype (InputNormalizer -> Decoder PackagesDir
forall a. (InputNormalizer -> Decoder a) -> FromDhall a
autoWith :: InputNormalizer -> Decoder PackagesDir
$cautoWith :: InputNormalizer -> Decoder PackagesDir
FromDhall, InputNormalizer -> Encoder PackagesDir
forall a. (InputNormalizer -> Encoder a) -> ToDhall a
injectWith :: InputNormalizer -> Encoder PackagesDir
$cinjectWith :: InputNormalizer -> Encoder PackagesDir
ToDhall)

$(deriveLift 'MkPackagesDir)

mkPackagesDir :: FilePath -> Q Exp
mkPackagesDir :: String -> Q Exp
mkPackagesDir = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => String -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) (forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path Rel Dir -> PackagesDir
MkPackagesDir) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadThrow m => String -> m (Path Rel Dir)
parseRelDir