module Dalmatian
  class RdsTest
    include Testable

    def initialize(
      rds:,
      env:,
      helper: Helper,
      logger: Logger,
      terraform: Terraform
    )
      @rds = rds
      @env = env
      @helper = helper
      @logger = logger
      @terraform = terraform
    end

    private

    attr_reader :rds, :env, :helper, :logger, :terraform

    def env_config
      env_details.merge(
        "account_id" => rds.account_id,
        "infrastructure_name" => rds.cluster_id,
        "dalmatian_role" => "dalmatian-read",
        "environment" => env_name,
        "rds" => {
          "identifier" => rds.identifier,
          "in_use_by" => rds.in_use_by,
          "clusters_in_use" => rds.clusters_in_use,
          "instance_class" => rds.instance_class,
          "engine" => rds.engine,
          "engine_version" => rds.engine_version,
          "allocated_storage" => rds.allocated_storage,
          "storage_encrypted" => rds.storage_encrypted,
          "storage_type" => rds.storage_type,
          "db_name" => rds.db_name,
          "port" => rds.port,
          "maintenance_window" => rds.maintenance_window,
          "backup_window" => rds.backup_window,
          "backup_retention_period" => rds.backup_retention_period,
          "force_ssl" => rds.force_ssl,
          "parameter_store_path_db_url_name" => rds.parameter_store_path_db_url_name,
          "sql_backup_scheduled_task_environment_variables" => rds.sql_backup_scheduled_task_environment_variables,
          "check_sql_backup_scheduled_task_environment_variables" => rds.check_sql_backup_scheduled_task_environment_variables,
          "sync_sql_backup_to_azure" => rds.sync_sql_backup_to_azure,
          "codebuild_access" => rds.codebuild_access
        }
      )
    end

    def checkout_revision_if_required
      false
    end

    def workspace_name
      [rds.cluster_id, rds.identifier, "rds", env_name].join("-")
    end

    def target_directory
      File.join(
        Infrastructure::APP_ROOT,
        Infrastructure::PATH,
        "rds"
      )
    end
  end
end
