module Dalmatian
  class AuroraTest
    include Testable

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

    private

    attr_reader :aurora, :env, :helper, :logger, :terraform

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

    def checkout_revision_if_required
      false
    end

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

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