// Copyright 2020 Google LLC
//
// 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.api.generator.gapic.model;

import com.google.api.generator.gapic.utils.ResourceNameConstants;
import com.google.auto.value.AutoValue;

@AutoValue
public abstract class ResourceReference {

  public abstract String resourceTypeString();

  public abstract boolean isChildType();

  public boolean isOnlyWildcard() {
    return resourceTypeString().equals(ResourceNameConstants.WILDCARD_PATTERN);
  }

  public static ResourceReference withType(String resourceTypeString) {
    return builder().setResourceTypeString(resourceTypeString).setIsChildType(false).build();
  }

  public static ResourceReference withChildType(String resourceTypeString) {
    return builder().setResourceTypeString(resourceTypeString).setIsChildType(true).build();
  }

  // Private.
  static Builder builder() {
    return new AutoValue_ResourceReference.Builder();
  }

  // Private.
  @AutoValue.Builder
  abstract static class Builder {
    abstract Builder setResourceTypeString(String resourceTypeString);

    abstract Builder setIsChildType(boolean isChildType);

    abstract ResourceReference build();
  }
}

@@ -994,32 +994,553 @@
 _PATTERN);%0A  %7D%0A%0A
+  @Override%0A  public boolean equals(Object o) %7B%0A    if (!(o instanceof ResourceReference)) %7B%0A      return false;%0A    %7D%0A%0A    ResourceReference other = (ResourceReference) o;%0A    return resourceTypeString().equals(other.resourceTypeString())%0A        && isChildType() == other.isChildType()%0A        && isOnlyWildcard() == other.isOnlyWildcard();%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return 17 * resourceTypeString().hashCode()%0A        + (isChildType() ? 1 : 0) * 19%0A        + (isOnlyWildcard() ? 1 : 0) * 31;%0A  %7D%0A%0A
   public static 

add equals() and hashCode() overrides for ResourceReference (#596)