import {
	type DomainSchema,
	type Schema,
	type Template,
	generateRandomDomain,
} from "../utils";

export function generate(schema: Schema): Template {
	const mainDomain = generateRandomDomain(schema);

	const domains: DomainSchema[] = [
		{ host: mainDomain, port: 80, serviceName: "appwrite", path: "/" },
		{
			host: mainDomain,
			port: 80,
			serviceName: "appwrite-console",
			path: "/console",
		},
		{
			host: mainDomain,
			port: 80,
			serviceName: "appwrite-realtime",
			path: "/v1/realtime",
		},
	];

	const envs = [
		"_APP_ENV=production",
		"_APP_LOCALE=en",
		"_APP_OPTIONS_ABUSE=enabled",
		"_APP_OPTIONS_FORCE_HTTPS=disabled",
		"_APP_OPTIONS_FUNCTIONS_FORCE_HTTPS=disabled",
		"_APP_OPTIONS_ROUTER_PROTECTION=disabled",
		"_APP_OPENSSL_KEY_V1=your-secret-key",
		`_APP_DOMAIN=${mainDomain}`,
		`_APP_DOMAIN_FUNCTIONS=${mainDomain}`,
		`_APP_DOMAIN_TARGET=${mainDomain}`,
		"_APP_CONSOLE_WHITELIST_ROOT=enabled",
		"_APP_CONSOLE_WHITELIST_EMAILS=",
		"_APP_CONSOLE_WHITELIST_IPS=",
		"_APP_CONSOLE_HOSTNAMES=",
		"_APP_SYSTEM_EMAIL_NAME=Appwrite",
		"_APP_SYSTEM_EMAIL_ADDRESS=noreply@appwrite.io",
		"_APP_SYSTEM_TEAM_EMAIL=team@appwrite.io",
		"_APP_SYSTEM_RESPONSE_FORMAT=",
		"_APP_SYSTEM_SECURITY_EMAIL_ADDRESS=certs@appwrite.io",
		"_APP_EMAIL_SECURITY=",
		"_APP_EMAIL_CERTIFICATES=",
		"_APP_USAGE_STATS=enabled",
		"_APP_LOGGING_PROVIDER=",
		"_APP_LOGGING_CONFIG=",
		"_APP_USAGE_AGGREGATION_INTERVAL=30",
		"_APP_USAGE_TIMESERIES_INTERVAL=30",
		"_APP_USAGE_DATABASE_INTERVAL=900",
		"_APP_WORKER_PER_CORE=6",
		"_APP_CONSOLE_SESSION_ALERTS=disabled",
		"_APP_REDIS_HOST=redis",
		"_APP_REDIS_PORT=6379",
		"_APP_REDIS_USER=",
		"_APP_REDIS_PASS=",
		"_APP_DB_HOST=mariadb",
		"_APP_DB_PORT=3306",
		"_APP_DB_SCHEMA=appwrite",
		"_APP_DB_USER=user",
		"_APP_DB_PASS=password",
		"_APP_DB_ROOT_PASS=rootsecretpassword",
		"_APP_INFLUXDB_HOST=influxdb",
		"_APP_INFLUXDB_PORT=8086",
		"_APP_STATSD_HOST=telegraf",
		"_APP_STATSD_PORT=8125",
		"_APP_SMTP_HOST=",
		"_APP_SMTP_PORT=",
		"_APP_SMTP_SECURE=",
		"_APP_SMTP_USERNAME=",
		"_APP_SMTP_PASSWORD=",
		"_APP_SMS_PROVIDER=",
		"_APP_SMS_FROM=",
		"_APP_STORAGE_LIMIT=30000000",
		"_APP_STORAGE_PREVIEW_LIMIT=20000000",
		"_APP_STORAGE_ANTIVIRUS=disabled",
		"_APP_STORAGE_ANTIVIRUS_HOST=clamav",
		"_APP_STORAGE_ANTIVIRUS_PORT=3310",
		"_APP_STORAGE_DEVICE=local",
		"_APP_STORAGE_S3_ACCESS_KEY=",
		"_APP_STORAGE_S3_SECRET=",
		"_APP_STORAGE_S3_REGION=us-east-1",
		"_APP_STORAGE_S3_BUCKET=",
		"_APP_STORAGE_DO_SPACES_ACCESS_KEY=",
		"_APP_STORAGE_DO_SPACES_SECRET=",
		"_APP_STORAGE_DO_SPACES_REGION=us-east-1",
		"_APP_STORAGE_DO_SPACES_BUCKET=",
		"_APP_STORAGE_BACKBLAZE_ACCESS_KEY=",
		"_APP_STORAGE_BACKBLAZE_SECRET=",
		"_APP_STORAGE_BACKBLAZE_REGION=us-west-004",
		"_APP_STORAGE_BACKBLAZE_BUCKET=",
		"_APP_STORAGE_LINODE_ACCESS_KEY=",
		"_APP_STORAGE_LINODE_SECRET=",
		"_APP_STORAGE_LINODE_REGION=eu-central-1",
		"_APP_STORAGE_LINODE_BUCKET=",
		"_APP_STORAGE_WASABI_ACCESS_KEY=",
		"_APP_STORAGE_WASABI_SECRET=",
		"_APP_STORAGE_WASABI_REGION=eu-central-1",
		"_APP_STORAGE_WASABI_BUCKET=",
		"_APP_FUNCTIONS_SIZE_LIMIT=30000000",
		"_APP_FUNCTIONS_BUILD_SIZE_LIMIT=2000000000",
		"_APP_FUNCTIONS_TIMEOUT=900",
		"_APP_FUNCTIONS_BUILD_TIMEOUT=900",
		"_APP_FUNCTIONS_CONTAINERS=10",
		"_APP_FUNCTIONS_CPUS=0",
		"_APP_FUNCTIONS_MEMORY=0",
		"_APP_FUNCTIONS_MEMORY_SWAP=0",
		"_APP_FUNCTIONS_RUNTIMES=node-16.0,php-8.0,python-3.9,ruby-3.0",
		"_APP_EXECUTOR_SECRET=your-secret-key",
		"_APP_EXECUTOR_HOST=http://exc1/v1",
		"_APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes",
		"_APP_FUNCTIONS_ENVS=node-16.0,php-7.4,python-3.9,ruby-3.0",
		"_APP_FUNCTIONS_INACTIVE_THRESHOLD=60",
		"DOCKERHUB_PULL_USERNAME=",
		"DOCKERHUB_PULL_PASSWORD=",
		"DOCKERHUB_PULL_EMAIL=",
		"OPEN_RUNTIMES_NETWORK=appwrite_runtimes",
		"_APP_FUNCTIONS_RUNTIMES_NETWORK=runtimes",
		"_APP_DOCKER_HUB_USERNAME=",
		"_APP_DOCKER_HUB_PASSWORD=",
		"_APP_FUNCTIONS_MAINTENANCE_INTERVAL=3600",
		"_APP_VCS_GITHUB_APP_NAME=",
		"_APP_VCS_GITHUB_PRIVATE_KEY=",
		"_APP_VCS_GITHUB_APP_ID=",
		"_APP_VCS_GITHUB_CLIENT_ID=",
		"_APP_VCS_GITHUB_CLIENT_SECRET=",
		"_APP_VCS_GITHUB_WEBHOOK_SECRET=",
		"_APP_MAINTENANCE_INTERVAL=86400",
		"_APP_MAINTENANCE_DELAY=0",
		"_APP_MAINTENANCE_RETENTION_CACHE=2592000",
		"_APP_MAINTENANCE_RETENTION_EXECUTION=1209600",
		"_APP_MAINTENANCE_RETENTION_AUDIT=1209600",
		"_APP_MAINTENANCE_RETENTION_ABUSE=86400",
		"_APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000",
		"_APP_MAINTENANCE_RETENTION_SCHEDULES=86400",
		"_APP_GRAPHQL_MAX_BATCH_SIZE=10",
		"_APP_GRAPHQL_MAX_COMPLEXITY=250",
		"_APP_GRAPHQL_MAX_DEPTH=3",
		"_APP_MIGRATIONS_FIREBASE_CLIENT_ID=",
		"_APP_MIGRATIONS_FIREBASE_CLIENT_SECRET=",
		"_APP_ASSISTANT_OPENAI_API_KEY=",
	];

	return {
		domains,
		envs,
		mounts: [],
	};
}
