module MastersRegistry
  class BasePage < UniversalPage
    def entries_for_isrc(isrc)
      params = {
        table_name: "qa-masters_audit_new",
        projection_expression: "#isrc, #timestamp",
        key_condition_expression: "#isrc = :isrc and #timestamp between :timestamp_a and :timestamp_b",
        expression_attribute_names: {
          "#isrc" => "isrc",
          "#timestamp" => "timestamp"
        },
        expression_attribute_values: {
          ":isrc" => isrc,
          ":timestamp_a" => (Date.today - 90).to_time.to_f * 1000,
          ":timestamp_b" => (Time.now.to_f * 1000).to_i
        }
      }
      Support::DynamoDbClient.query_dynamodb(params).items
    end

    def delete_all_entries(entries)
      entries.each do |entry|
        params = {
          table_name: "qa-masters_audit_new",
          key: {
            isrc: entry["isrc"],
            timestamp: entry["timestamp"].to_f
          }
        }
        Support::DynamoDbClient.delete_dynamodb_record(params)
      end
    end
  end
end
