// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.server.group.db;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

// TODO(aliceks): Add Javadoc descriptions to this file.
@AutoValue
public abstract class InternalGroupUpdate {
  public abstract Optional<AccountGroup.NameKey> getName();

  // TODO(aliceks): Mention empty string (not null!) -> unset value in Javadoc.
  public abstract Optional<String> getDescription();

  public abstract Optional<AccountGroup.UUID> getOwnerGroupUUID();

  public abstract Optional<Boolean> getVisibleToAll();

  public abstract Function<ImmutableSet<Account.Id>, ? extends Set<Account.Id>>
      getMemberModification();

  public abstract Function<ImmutableSet<AccountGroup.UUID>, ? extends Set<AccountGroup.UUID>>
      getSubgroupModification();

  public static Builder builder() {
    return new AutoValue_InternalGroupUpdate.Builder()
        .setMemberModification(Function.identity())
        .setSubgroupModification(Function.identity());
  }

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder setName(AccountGroup.NameKey name);

    public abstract Builder setDescription(String description);

    public abstract Builder setOwnerGroupUUID(AccountGroup.UUID ownerGroupUUID);

    public abstract Builder setVisibleToAll(boolean visibleToAll);

    public abstract Builder setMemberModification(
        Function<ImmutableSet<Account.Id>, ? extends Set<Account.Id>> memberModification);

    public abstract Builder setSubgroupModification(
        Function<ImmutableSet<AccountGroup.UUID>, ? extends Set<AccountGroup.UUID>>
            subgroupModification);

    public abstract InternalGroupUpdate build();
  }
}

@@ -890,44 +890,8 @@
 Set;
-%0Aimport java.util.function.Function;
 %0A%0A//
@@ -1000,16 +1000,280 @@
 pdate %7B%0A
+  @FunctionalInterface%0A  public interface MemberModification %7B%0A    Set%3CAccount.Id%3E apply(ImmutableSet%3CAccount.Id%3E in);%0A  %7D%0A%0A  @FunctionalInterface%0A  public interface SubgroupModification %7B%0A    Set%3CAccountGroup.UUID%3E apply(ImmutableSet%3CAccountGroup.UUID%3E in);%0A  %7D%0A%0A
   public
@@ -1605,201 +1605,91 @@
 act 
-Function%3CImmutableSet%3CAccount.Id%3E, ? extends Set%3CAccount.Id%3E%3E%0A      getMemberModification();%0A%0A  public abstract Function%3CImmutableSet%3CAccountGroup.UUID%3E, ? extends Set%3CAccountGroup.UUID%3E%3E%0A     
+MemberModification getMemberModification();%0A%0A  public abstract SubgroupModification
  get
@@ -1835,35 +1835,24 @@
 ication(
-Function.identity()
+in -%3E in
 )%0A      
@@ -1882,27 +1882,16 @@
 ion(
-Function.identity()
+in -%3E in
 );%0A 
@@ -2290,78 +2290,26 @@
 ion(
-%0A        Function%3CImmutableSet%3CAccount.Id%3E, ? extends Set%3CAccount.Id%3E%3E
+MemberModification
  mem
@@ -2383,104 +2383,28 @@
 ion(
-%0A        Function%3CImmutableSet%3CAccountGroup.UUID%3E, ? extends Set%3CAccountGroup.UUID%3E%3E%0A           
+SubgroupModification
  sub

Use named types for modification functions