(import ../lib.nix) {
  name = "think-gtcm";
  nodes =
    let
      settings = {

        DB_CONNECTION = "mysql";
        DB_HOST = "localhost";
        DB_PORT = 3306;
        DB_DATABASE = "thinkgtcm";
        DB_USERNAME = "gtcm";
        DB_PASSWORD = "";

        APP_NAME = "Laravel";
        APP_ENV = "local";
        APP_DEBUG = "false";
        APP_URL = "http://localhost";

        LOG_CHANNEL = "stack";
        LOG_LEVEL = "debug";

        BROADCAST_DRIVER = "log";
        CACHE_DRIVER = "file";
        FILESYSTEM_DISK = "local";
        QUEUE_CONNECTION = "sync";
        SESSION_DRIVER = "file";
        SESSION_LIFETIME = "120";

        MEMCACHED_HOST = "127.0.0.1";

        REDIS_HOST = "127.0.0.1";
        REDIS_PASSWORD = "null";
        REDIS_PORT = "6379";

        MAIL_MAILER = "smtp";
        MAIL_HOST = "mailpit";
        MAIL_PORT = "1025";
        MAIL_USERNAME = "null";
        MAIL_PASSWORD = "null";
        MAIL_ENCRYPTION = "null";
        MAIL_FROM_ADDRESS = "hello@example.com";

        AWS_DEFAULT_REGION = "us-east-1";
        AWS_USE_PATH_STYLE_ENDPOINT = "false";

        PUSHER_PORT = 443;
        PUSHER_SCHEME = "https";
        PUSHER_APP_CLUSTER = "mt1";

        UPLOAD_MAX_FILESIZE = "5000M";
        POST_MAX_SIZE = "5000M";

        TEST_LOCAL = "false";
      };
    in
    {
      gtcm1 =
        { self, ... }:
        {
          nixpkgs.overlays = [ self.overlays.packagesOverlay ];
          imports = [ self.nixosModules.think-gtcm ];
          services.think-greaterchiangmai = {
            enable = true;
            settings = settings // {
              APP_SERVICES_CACHE = "/run/think-gtcm/cache/services.php";
              APP_PACKAGES_CACHE = "/run/think-gtcm/cache/packages.php";
              APP_CONFIG_CACHE = "/run/think-gtcm/cache/config.php";
              APP_ROUTES_CACHE = "/run/think-gtcm/cache/routes-v7.php";
              APP_EVENTS_CACHE = "/run/think-gtcm/cache/events.php";
            };
          };
        };
      backend1 =
        { self, ... }:
        {
          nixpkgs.overlays = [ self.overlays.packagesOverlay ];
          imports = [ self.nixosModules.think-backend-gtcm ];
          services.think-backend-greaterchiangmai = {
            enable = true;
            settings = settings // {
              APP_SERVICES_CACHE = "/run/think-backend-gtcm/cache/services.php";
              APP_PACKAGES_CACHE = "/run/think-backend-gtcm/cache/packages.php";
              APP_CONFIG_CACHE = "/run/think-backend-gtcm/cache/config.php";
              APP_ROUTES_CACHE = "/run/think-backend-gtcm/cache/routes-v7.php";
              APP_EVENTS_CACHE = "/run/think-backend-gtcm/cache/events.php";
            };
          };
        };
    };
  # This is the test code that will check if our service is running correctly:
  testScript = ''
    start_all()

    gtcm1.wait_for_unit("phpfpm-think-gtcm")
    gtcm1.wait_for_open_port(80)
    output = gtcm1.succeed("curl localhost")

    backend1.wait_for_unit("phpfpm-think-backend-gtcm")
    backend1.wait_for_open_port(80)
    output = backend1.succeed("curl localhost")
  '';
}
