package com.google.sps.data;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public final class VolunteeringOpportunity {
  private String opportunityId;
  private String eventId;
  private String name;
  private int numSpotsLeft;
  private Set<String> requiredSkills;
  private Set<User> volunteers;

  public static class Builder {
    // Required parameters
    private String opportunityId = UUID.randomUUID().toString();
    private String eventId;
    private String name;
    private int numSpotsLeft;

    // Optional parameters
    private Set<String> requiredSkills;
    private Set<User> volunteers;

    public Builder(String eventId, String name, int numSpotsLeft) {
      this.eventId = eventId;
      this.name = name;
      this.numSpotsLeft = numSpotsLeft;
      this.requiredSkills = new HashSet<>();
      this.volunteers = new HashSet<>();
    }

    public Builder setOpportunityId(String opportunityId) {
      this.opportunityId = opportunityId;
      return this;
    }

    public Builder setName(String name) {
      this.name = name;
      return this;
    }

    public Builder setNumSpotsLeft(int numSpotsLeft) {
      this.numSpotsLeft = numSpotsLeft;
      return this;
    }

    public Builder setRequiredSkills(Set<String> requiredSkills) {
      this.requiredSkills = requiredSkills;
      return this;
    }

    public Builder addRequiredSkill(String requiredSkill) {
      this.requiredSkills.add(requiredSkill);
      return this;
    }

    public Builder removeRequiredSkill(String requiredSkill) {
      this.requiredSkills.remove(requiredSkill);
      return this;
    }

    public Builder setVolunteers(Set<User> volunteers) {
      this.volunteers = volunteers;
      return this;
    }

    public Builder addVolunteer(User volunteer) {
      this.volunteers.add(volunteer);
      return this;
    }

    public Builder removeVolunteer(User volunteer) {
      this.volunteers.remove(volunteer);
      return this;
    }

    public VolunteeringOpportunity build() {
      return new VolunteeringOpportunity(this);
    }

    public Builder mergeFrom(VolunteeringOpportunity other) {
      this.opportunityId = other.getOpportunityId();
      this.eventId = other.getEventId();
      this.name = other.getName();
      this.numSpotsLeft = other.getNumSpotsLeft();

      if (!other.getRequiredSkills().isEmpty()) {
        this.requiredSkills = other.getRequiredSkills();
      }
      if (!other.getVolunteers().isEmpty()) {
        this.volunteers = other.getVolunteers();
      }
      return this;
    }
  }

  private VolunteeringOpportunity(Builder builder) {
    opportunityId = builder.opportunityId;
    eventId = builder.eventId;
    name = builder.name;
    numSpotsLeft = builder.numSpotsLeft;
    requiredSkills = builder.requiredSkills;
    volunteers = builder.volunteers;
  }

  public String getOpportunityId() {
    return this.opportunityId;
  }

  public String getEventId() {
    return this.eventId;
  }

  public String getName() {
    return this.name;
  }

  public Set<String> getRequiredSkills() {
    return this.requiredSkills;
  }

  public int getNumSpotsLeft() {
    return this.numSpotsLeft;
  }

  public Set<User> getVolunteers() {
    return this.volunteers;
  }

  public Builder toBuilder() {
    return new Builder(this.eventId, this.name, this.numSpotsLeft).mergeFrom(this);
  }

  @Override
  public String toString() {
    return String.format("Name: %s\nNumber of spots left: %d\n", this.name, this.numSpotsLeft);
  }
}

@@ -74,31 +74,8 @@
 Set;
-%0Aimport java.util.UUID;
 %0A%0Apu
@@ -119,36 +119,40 @@
 ity %7B%0A  private 
-Stri
+final lo
 ng opportunityId
@@ -155,35 +155,98 @@
 tyId
-;%0A  private String eventId;
+ =%0A    10000000L; // TODO: Needed for storing ID from DB, replace using ID generated by DB
 %0A  p
@@ -427,101 +427,8 @@
 ers%0A
-    private String opportunityId = UUID.randomUUID().toString();%0A    private String eventId;%0A
     
@@ -611,24 +611,8 @@
 ing 
-eventId, String 
 name
@@ -637,38 +637,8 @@
 ) %7B%0A
-      this.eventId = eventId;%0A
     
@@ -794,136 +794,8 @@
  %7D%0A%0A
-    public Builder setOpportunityId(String opportunityId) %7B%0A      this.opportunityId = opportunityId;%0A      return this;%0A    %7D%0A%0A
     
@@ -1929,102 +1929,8 @@
 ) %7B%0A
-      this.opportunityId = other.getOpportunityId();%0A      this.eventId = other.getEventId();%0A
     
@@ -2317,82 +2317,8 @@
 ) %7B%0A
-    opportunityId = builder.opportunityId;%0A    eventId = builder.eventId;%0A
     
@@ -2471,28 +2471,26 @@
 %7D%0A%0A  public 
-Stri
+lo
 ng getOpport
@@ -2541,69 +2541,8 @@
  %7D%0A%0A
-  public String getEventId() %7B%0A    return this.eventId;%0A  %7D%0A%0A
   pu
@@ -2868,22 +2868,8 @@
 der(
-this.eventId, 
 this

Revert "Add missing setter for opportunityId to VolunteeringOpporutnity."