class Multiwoven::Integrations::Destination::GoogleSheets::Client

def clear_all_records(sync_config)

def clear_all_records(sync_config)
  setup_write_environment(sync_config, "clear")
  connection_specification = sync_config.destination.connection_specification.with_indifferent_access
  spreadsheet = fetch_google_spread_sheets(connection_specification)
  sheet_ids = spreadsheet.sheets.map(&:properties).map(&:sheet_id)
  delete_extra_sheets(sheet_ids)
  unless sheet_ids.empty?
    clear_response = clear_sheet_data(spreadsheet.sheets.first.properties.title)
    return control_message("Successfully cleared data.", "succeeded") if clear_response&.cleared_range
  end
  control_message("Failed to clear data.", "failed")
rescue StandardError => e
  control_message(e.message, "failed")
end