# frozen_string_literal: true

module Neetob
  class CLI
    module MonthlyAudit
      module Misc
        class SparkpostSubAccountUsedForAllApps < CLI::Base
          APPS_TO_IGNORE = ["neeto-wheel-web"]

          def initialize
            super()
          end

          def run
            repo_data = [["App",
"SPARKPOST_PASSWORD env variable first 4 characters same as corresponding sub-account in Sparkpost dashboard", "Comments", "Audit Passed"]]
            ui.info "\n"
            ui.info "#### Please manually check and add Yes/No for all the following checks:"
            ui.info "- Get the first 4 characters of the SPARKPOST_PASSWORD environment variable for the app"
            ui.info "- Go to https://app.sparkpost.com/account/api-keys"
            ui.info "- Match the first 4 characters against the API keys values"
            ui.info "- Verify that the API key belongs to the subaccount for same app. Accordingly add Yes/No in the 2nd column"
            ui.info "- Finally, set Audit Passed as Yes only if the last check passed, otherwise set it as No and add a comment in the Comments column"
            ui.info "\n"
            NeetoCompliance::NeetoRepos.products.keys.each do |repo|
              repo_data << (
                APPS_TO_IGNORE.include?(repo) ?
                [repo, "No", "App ignored from this check", "Ignored"] :
                [repo, nil, nil, nil]
              )
            end
            ui.print_table(repo_data)
          end
        end
      end
    end
  end
end