processConfig :: Config -> Either [ConfigError] ProcessedConfig
processConfig config =
  let
    inboxHandlerCommands' :: Maybe [InboxHandlerCommandSpec]
    inboxHandlerCommands' = commands =<< handlerSpecInbox (handlers config)

    (ihcErrors, ihcSuccesses) = processInboxCommandHandlers inboxHandlerCommands'

    inboxRefileDests' :: Maybe [InboxHandlerRefileDestSpec]
    inboxRefileDests' = refileDests =<< handlerSpecInbox (handlers config)

    (refileErrors, refileDests') = processRefileDests inboxRefileDests'

    gitHandlerCommands' :: Maybe [GitHandlerCommandSpec]
    gitHandlerCommands' = gitCommands =<< handlerSpecGit (handlers config)

    (ghcErrors, ghcSuccesses) = processGitCommandHandlers gitHandlerCommands'

    allErrors = ihcErrors ++ refileErrors ++ ghcErrors

    newConfig = ProcessedConfig
      { rawConfig = config
      , inboxHandlerCommands = ihcSuccesses
      , inboxRefileDests = refileDests'
      , gitHandlerCommands = ghcSuccesses
      }
  in
    if List.length allErrors > 0 then
      Left allErrors
    else
      Right newConfig
processConfig :: Config -> Either [ConfigError] ProcessedConfig
processConfig config =
  let
    inboxHandlerCommands' :: Maybe [InboxHandlerCommandSpec]
    inboxHandlerCommands' = commands =<< handlerSpecInbox (handlers config)

    (ihcErrors, ihcSuccesses) = processInboxCommandHandlers inboxHandlerCommands'

    inboxRefileDests' :: Maybe [InboxHandlerRefileDestSpec]
    inboxRefileDests' = refileDests =<< handlerSpecInbox (handlers config)

    (refileErrors, refileDests') = processRefileDests inboxRefileDests'

    gitHandlerCommands' :: Maybe [GitHandlerCommandSpec]
    gitHandlerCommands' = gitCommands =<< handlerSpecGit (handlers config)

    (ghcErrors, ghcSuccesses) = processGitCommandHandlers gitHandlerCommands'

    allErrors = ihcErrors ++ refileErrors ++ ghcErrors

    newConfig = ProcessedConfig
      { rawConfig = config
      , inboxHandlerCommands = ihcSuccesses
      , inboxRefileDests = refileDests'
      , gitHandlerCommands = ghcSuccesses
      }
  in
    if List.length allErrors > 0 then
      Left allErrors
    else
      Right newConfig
processConfig config =
  let
    inboxHandlerCommands' :: Maybe [InboxHandlerCommandSpec]
    inboxHandlerCommands' = commands =<< handlerSpecInbox (handlers config)

    (ihcErrors, ihcSuccesses) = processInboxCommandHandlers inboxHandlerCommands'

    inboxRefileDests' :: Maybe [InboxHandlerRefileDestSpec]
    inboxRefileDests' = refileDests =<< handlerSpecInbox (handlers config)

    (refileErrors, refileDests') = processRefileDests inboxRefileDests'

    gitHandlerCommands' :: Maybe [GitHandlerCommandSpec]
    gitHandlerCommands' = gitCommands =<< handlerSpecGit (handlers config)

    (ghcErrors, ghcSuccesses) = processGitCommandHandlers gitHandlerCommands'

    allErrors = ihcErrors ++ refileErrors ++ ghcErrors

    newConfig = ProcessedConfig
      { rawConfig = config
      , inboxHandlerCommands = ihcSuccesses
      , inboxRefileDests = refileDests'
      , gitHandlerCommands = ghcSuccesses
      }
  in
    if List.length allErrors > 0 then
      Left allErrors
    else
      Right newConfig