module KPM::Tasks

def diagnostic

def diagnostic
  logger.info 'Please wait processing the request!!!'
  begin
    if options[:account_export] && options[:account_export] == 'account_export'
      raise Interrupt,'--account_export,  please provide a valid account id'
    end
    if options[:killbill_url] && /https?:\/\/[\S]+/.match(options[:killbill_url]).nil?
      raise Interrupt,'--killbill_url, required format -> http(s)://something'
    end
    if options[:killbill_api_credentials] && options[:killbill_api_credentials].size != 2
      raise Interrupt,'--killbill_api_credentials, required format -> <api_key> <api_secrets>'
    end
    if options[:killbill_credentials] && options[:killbill_credentials].size != 2
      raise Interrupt,'--killbill_credentials, required format -> <user> <password>'
    end
    if options[:database_credentials] && options[:database_credentials].size != 2
      raise Interrupt,'--database_credentials, required format -> <user> <password>'
    end
    if options[:database_name] && options[:database_name] == :database_name.to_s
      raise Interrupt,'--database_credentials, please provide a valid database name'
    end
    if options[:kaui_web_path] && options[:kaui_web_path] == :kaui_web_path.to_s
      raise Interrupt,'--kaui_web_path, please provide a valid kaui web path '
    end
    if options[:killbill_web_path] && options[:killbill_web_path] == :killbill_web_path.to_s
      raise Interrupt,'--killbill_web_path, please provide a valid killbill web path'
    end
    diagnostic = KPM::DiagnosticFile.new(options[:config_file],options[:killbill_api_credentials],options[:killbill_credentials],
                               options[:killbill_url],options[:database_name],options[:database_credentials],
                              options[:database_host], options[:database_port], options[:kaui_web_path], options[:killbill_web_path], options[:bundles_dir],logger)
    diagnostic.export_data(options[:account_export],  options[:log_dir])
  rescue Exception => e
    logger.error "\e[91;1m#{e.message}\e[0m"
    if not e.is_a?(Interrupt)
      logger.error e.backtrace.join("\n")
    end
  end
end