package com.google.sps.utilities;

import com.google.cloud.spanner.Database;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;

/** Class containing methods for interaction with database for tests. */
public class SpannerTestTasks {
  public static void setup() throws InterruptedException, ExecutionException {
    Iterable<String> statements =
        Arrays.asList(
            "CREATE TABLE Users ("
                + "  Name                 STRING(MAX) NOT NULL,"
                + "  Email                STRING(MAX) NOT NULL,"
                + "  Interests            ARRAY<STRING(MAX)>,"
                + "  Skills               ARRAY<STRING(MAX)>,"
                + "  EventsHosting        ARRAY<STRING(MAX)>,"
                + "  EventsParticipating  ARRAY<STRING(MAX)>,"
                + "  EventsVolunteering   ARRAY<STRING(MAX)>,"
                + "  Image                STRING(MAX)"
                + ") PRIMARY KEY (Email)",
            "CREATE TABLE Events ("
                + "  EventID        STRING(MAX) NOT NULL,"
                + "  Name           STRING(MAX) NOT NULL,"
                + "  Description    STRING(MAX),"
                + "  Date           DATE,"
                + "  Location       STRING(MAX),"
                + "  Attendees      ARRAY<STRING(MAX)>,"
                + "  Host           STRING(MAX),"
                + "  Time           STRING(MAX),"
                + "  Labels         ARRAY<STRING(MAX)>,"
                + "  Opportunities  ARRAY<STRING(MAX)>,"
                + "  Image          STRING(MAX),"
                + ") PRIMARY KEY (EventID)",
            "CREATE TABLE VolunteeringOpportunity ("
                + "  VolunteeringOpportunityID  STRING(MAX) NOT NULL,"
                + "  EventID                    STRING(MAX) NOT NULL,"
                + "  Name                       STRING(MAX) NOT NULL,"
                + "  NumSpotsLeft               INT64 NOT NULL,"
                + "  RequiredSkills             ARRAY<STRING(MAX)>,"
                + "  Volunteers                 ARRAY<STRING(MAX)>"
                + ") PRIMARY KEY (VolunteeringOpportunityID)",
            "CREATE TABLE OpportunitySignup ("
	          + "  VolunteeringOpportunityID  STRING(MAX) NOT NULL,"
	          + "  Email                      STRING(MAX) NOT NULL,"
                + ") PRIMARY KEY (VolunteeringOpportunityID, Email)");
    Database db =
        SpannerClient.getDatabaseAdminClient()
            .createDatabase(
                SpannerClient.getInstanceId(), SpannerClient.getDatabaseId(), statements)
            .get();
  }

  /* Drops the database */
  public static void cleanup() {
    SpannerClient.getDatabaseAdminClient()
        .dropDatabase(SpannerClient.getInstanceId(), SpannerClient.getDatabaseId());
  }
}

@@ -2404,16 +2404,511 @@
  Email)%22
+, %0A            %22CREATE TABLE Keywords (%22%0A            + %22  KeywordID STRING(MAX),%22%0A            + %22  Name STRING(MAX),%22%0A            + %22) PRIMARY KEY(KeywordID)%22,%0A            %22CREATE TABLE Results (%22%0A            + %22  KeywordID STRING(MAX),%22%0A            + %22  EventID STRING(MAX),%22%0A            + %22  Ranking FLOAT64,%22%0A            + %22  FOREIGN KEY(EventID) REFERENCES Events(EventID),%22%0A            + %22) PRIMARY KEY(KeywordID, EventID),%22%0A            + %22  INTERLEAVE IN PARENT Keywords ON DELETE CASCADE%22
 );%0A    D

Update Spanner Test Tasks for new tables