# frozen_string_literal: true

module Neetob
  class CLI
    module MonthlyAudit
      module InstancesAndAddons
        module Cloudflare
          class AlwaysUseHttpsIsEnabled < CLI::Base
            def initialize
              super()
            end

            def run
              ui.success "### 3.2.4. Checking whether always use HTTPS is enabled"

              domains_data = [["Domain", "Always use HTTPS", "Audit Passed"]]
              ui.info("\n", print_to_audit_log: false)
              Neetob::CLI::Cloudflare::Base::ZONE_IDS.keys.select { |domain|
 domain.to_s.include?(".com") }.map do |domain|
                ui.info("Checking Always use HTTPS value for #{domain}", print_to_audit_log: false)
                always_use_https_value = Neetob::CLI::Cloudflare::AlwaysUseHttps.new(domain).run
                audit_passed = always_use_https_value.to_s == "on" ? "Yes" : "No"
                domains_data << [domain, always_use_https_value, audit_passed]
              end
              ui.print_table(domains_data)
            end
          end
        end
      end
    end
  end
end