-- |
-- Module      : Git.Stale.Types.Env
-- License     : BSD3
-- Maintainer  : tbidne@gmail.com
-- Provides `Env` type.
module Git.Stale.Types.Env
  ( BranchType (..),
    Env (..),
    branchTypeToArg,
  )
where

import Common.RefinedUtils
import qualified Data.Text as T
import qualified Data.Time.Calendar as C
import qualified System.IO as IO

-- | Describes the branch type.
data BranchType
  = All
  | Remote
  | Local
  deriving (BranchType -> BranchType -> Bool
(BranchType -> BranchType -> Bool)
-> (BranchType -> BranchType -> Bool) -> Eq BranchType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BranchType -> BranchType -> Bool
$c/= :: BranchType -> BranchType -> Bool
== :: BranchType -> BranchType -> Bool
$c== :: BranchType -> BranchType -> Bool
Eq, Int -> BranchType -> ShowS
[BranchType] -> ShowS
BranchType -> String
(Int -> BranchType -> ShowS)
-> (BranchType -> String)
-> ([BranchType] -> ShowS)
-> Show BranchType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BranchType] -> ShowS
$cshowList :: [BranchType] -> ShowS
show :: BranchType -> String
$cshow :: BranchType -> String
showsPrec :: Int -> BranchType -> ShowS
$cshowsPrec :: Int -> BranchType -> ShowS
Show)

-- | Maps a `BranchType` to a `String` flag to be used in "Core.MonadFindBranches"'
-- `Core.MonadFindBranches.branchNamesByGrep` command.
branchTypeToArg :: BranchType -> String
branchTypeToArg :: BranchType -> String
branchTypeToArg All = "-a"
branchTypeToArg Remote = "-r"
branchTypeToArg Local = ""

-- | The Env type to be used with Reader.
data Env
  = Env
      { -- | A `String` to filter branch names on. `Just` /s/ if non-empty,
        -- `Nothing` otherwise.
        Env -> Maybe Text
grepStr :: Maybe T.Text,
        -- | The path of the git directory. `Just` /s/ if non-empty,
        -- `Nothing` otherwise.
        Env -> Maybe String
path :: Maybe IO.FilePath,
        -- | A non-negative integer descrbing stale threshold in days.
        Env -> RNonNegative Int
limit :: RNonNegative Int,
        -- | The type of branches to search.
        Env -> BranchType
branchType :: BranchType,
        -- | The name of the remote.
        Env -> Text
remoteName :: T.Text,
        -- | The name of the branch to consider merges against.
        Env -> Text
master :: T.Text,
        -- | Today's date.
        Env -> Day
today :: C.Day
      }
  deriving (Int -> Env -> ShowS
[Env] -> ShowS
Env -> String
(Int -> Env -> ShowS)
-> (Env -> String) -> ([Env] -> ShowS) -> Show Env
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Env] -> ShowS
$cshowList :: [Env] -> ShowS
show :: Env -> String
$cshow :: Env -> String
showsPrec :: Int -> Env -> ShowS
$cshowsPrec :: Int -> Env -> ShowS
Show)