module Ribosome.App.Templates where

import Exon (exon)
import Path (reldir, relfile)

import Ribosome.App.Data (
  Author,
  Branch,
  Cachix,
  FlakeUrl,
  Github,
  Maintainer,
  ProjectName,
  ProjectNames (..),
  Year,
  )
import Ribosome.App.Data.TemplateTree (TemplateTree (TDir, TFile))
import Ribosome.App.Templates.Boot (vimBoot)
import Ribosome.App.Templates.Flake (flakeNix)
import Ribosome.App.Templates.GithubActions (gaLatest, gaTags)
import Ribosome.App.Templates.Hpack (hpackNix)
import Ribosome.App.Templates.License (license)
import Ribosome.App.Templates.MainHs (mainHs)
import Ribosome.App.Templates.PingTestHs (pingTestHs)
import Ribosome.App.Templates.PluginHs (pluginHs)
import Ribosome.App.Templates.ReadmeMd (readmeMd)
import Ribosome.App.Templates.TestMainHs (testMainHs)

pluginDir ::
  ProjectName ->
  Maybe Github ->
  Maybe Cachix ->
  TemplateTree
pluginDir :: ProjectName -> Maybe Github -> Maybe Cachix -> TemplateTree
pluginDir ProjectName
name Maybe Github
github Maybe Cachix
cachix =
  Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|plugin|] [
    Path Rel File -> Text -> TemplateTree
TFile [relfile|boot.vim|] (ProjectName -> Maybe Github -> Maybe Cachix -> Text
vimBoot ProjectName
name Maybe Github
github Maybe Cachix
cachix)
  ]

newProjectTemplates ::
  ProjectNames ->
  FlakeUrl ->
  Author ->
  Maintainer ->
  Branch ->
  Maybe Github ->
  Maybe Cachix ->
  Year ->
  TemplateTree
newProjectTemplates :: ProjectNames
-> FlakeUrl
-> Author
-> Maintainer
-> Branch
-> Maybe Github
-> Maybe Cachix
-> Year
-> TemplateTree
newProjectTemplates ProjectNames {Path Rel Dir
ModuleName
ProjectName
$sel:moduleNameDir:ProjectNames :: ProjectNames -> Path Rel Dir
$sel:moduleName:ProjectNames :: ProjectNames -> ModuleName
$sel:nameDir:ProjectNames :: ProjectNames -> Path Rel Dir
$sel:name:ProjectNames :: ProjectNames -> ProjectName
moduleNameDir :: Path Rel Dir
moduleName :: ModuleName
nameDir :: Path Rel Dir
name :: ProjectName
..} FlakeUrl
flakeUrl Author
author Maintainer
maintainer Branch
branch Maybe Github
github Maybe Cachix
cachix Year
year =
  Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|.|] [
    Path Rel File -> Text -> TemplateTree
TFile [relfile|flake.nix|] (FlakeUrl
-> ProjectName -> Branch -> Maybe Github -> Maybe Cachix -> Text
flakeNix FlakeUrl
flakeUrl ProjectName
name Branch
branch Maybe Github
github Maybe Cachix
cachix),
    Path Rel File -> Text -> TemplateTree
TFile [relfile|readme.md|] (ProjectName -> Maybe Github -> Text
readmeMd ProjectName
name Maybe Github
github),
    Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|packages|] [
      Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir Path Rel Dir
nameDir [
        Path Rel File -> Text -> TemplateTree
TFile [relfile|LICENSE|] (Author -> Text
license Author
author),
        Path Rel File -> Text -> TemplateTree
TFile [relfile|readme.md|] (ProjectName -> Maybe Github -> Text
readmeMd ProjectName
name Maybe Github
github),
        Path Rel File -> Text -> TemplateTree
TFile [relfile|changelog.md|] Text
"# Unreleased",
        Path Rel File -> Text -> TemplateTree
TFile [relfile|app/Main.hs|] (ModuleName -> Text
mainHs ModuleName
moduleName),
        Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|lib|] [
          Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir Path Rel Dir
moduleNameDir [
            Path Rel File -> Text -> TemplateTree
TFile [relfile|Plugin.hs|] (ProjectName -> ModuleName -> Text
pluginHs ProjectName
name ModuleName
moduleName)
          ]
        ],
        Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|test|] [
          Path Rel File -> Text -> TemplateTree
TFile [relfile|Main.hs|] (ModuleName -> Text
testMainHs ModuleName
moduleName),
          Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir Path Rel Dir
moduleNameDir [
            Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|Test|] [
              Path Rel File -> Text -> TemplateTree
TFile [relfile|PingTest.hs|] (ModuleName -> Text
pingTestHs ModuleName
moduleName)
            ]
          ]
        ]
      ]
    ],
    Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|ops|] [
      Path Rel File -> Text -> TemplateTree
TFile [relfile|hpack.nix|] (ProjectName -> Author -> Maintainer -> Year -> Maybe Github -> Text
hpackNix ProjectName
name Author
author Maintainer
maintainer Year
year Maybe Github
github),
      Path Rel File -> Text -> TemplateTree
TFile [relfile|version.nix|] [exon|"0.1.0.0"|]
    ]
  ]

bootTemplates ::
  ProjectName ->
  Branch ->
  Maybe Github ->
  Maybe Cachix ->
  TemplateTree
bootTemplates :: ProjectName
-> Branch -> Maybe Github -> Maybe Cachix -> TemplateTree
bootTemplates ProjectName
name Branch
branch Maybe Github
github Maybe Cachix
cachix =
  Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|.|] [
    ProjectName -> Maybe Github -> Maybe Cachix -> TemplateTree
pluginDir ProjectName
name Maybe Github
github Maybe Cachix
cachix,
    Path Rel Dir -> [TemplateTree] -> TemplateTree
TDir [reldir|.github/workflows|] [
      Path Rel File -> Text -> TemplateTree
TFile [relfile|latest.yml|] (ProjectName -> Branch -> Maybe Cachix -> Text
gaLatest ProjectName
name Branch
branch Maybe Cachix
cachix),
      Path Rel File -> Text -> TemplateTree
TFile [relfile|tags.yml|] (ProjectName -> Maybe Cachix -> Text
gaTags ProjectName
name Maybe Cachix
cachix)
    ]
  ]