{ pkgs
, lib
, config
, namespace
, ...
}:
let
  inherit (lib) mkIf;
  cfg = config.${namespace}.programs.terminal.git;
in
{
  options.${namespace}.programs.terminal.git = {
    enable = lib.mkEnableOption "Git";
  };

  config = mkIf cfg.enable {
    programs.git = {
      enable = true;
      lfs.enable = true;
      settings = {
        aliases = {
          lg = "log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all -n 15";
        };
        user = {
          name = "Evan Reichard";
          email = "evan@reichard.io";
        };
        core = {
          autocrlf = "input";
          safecrlf = "true";
          excludesFile = "~/.config/git/.gitignore";
        };
        column = {
          ui = "auto";
        };
        fetch = {
          prune = true;
          pruneTags = true;
          all = true;
          forceUpdateTags = true;
        };
        help = {
          autocorrect = true;
        };
        diff = {
          algorithm = "histogram";
          colorMoved = "plain";
          mnemonicPrefix = true;
          renames = true;
        };
        rebase = {
          autoSquash = true;
          autoStash = true;
          updateRefs = true;
        };
        rerere = {
          enabled = true;
          autoupdate = true;
        };
        commit = {
          verbose = true;
        };
        branch = {
          sort = "-committerdate";
        };
        merge = {
          conflictstyle = "zdiff3";
        };
        push = {
          autoSetupRemote = true;
        };
      };
      includes = [
        {
          path = "~/.config/git/work";
          condition = "gitdir:~/Development/git/work/";
        }
        {
          path = "~/.config/git/personal";
          condition = "gitdir:~/Development/git/personal/";
        }
      ];
    };

    programs.gh = {
      enable = true;
      settings = {
        git_protocol = "ssh";
      };
    };

    home.packages = with pkgs; [ gh ];

    # Copy Configuration
    xdg.configFile = {
      git = {
        source = ./config;
        recursive = true;
      };
    };
  };
}
