/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * 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.facebook.buck.skylark.packages;

import com.facebook.buck.core.cell.name.CanonicalCellName;
import com.facebook.buck.core.model.label.PackageIdentifier;
import com.facebook.buck.core.model.label.PathFragment;
import com.facebook.buck.core.model.label.RepositoryName;
import com.facebook.buck.core.path.ForwardRelativePath;
import com.facebook.buck.core.util.immutables.BuckStyleValue;
import com.facebook.buck.skylark.io.Globber;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.events.EventHandler;
import java.util.Map;
import org.immutables.value.Value;

/** Exposes package information to Skylark functions. */
@BuckStyleValue
public abstract class PackageContext {
  /** Returns a globber instance that can resolve paths relative to current package. */
  public abstract Globber getGlobber();

  /**
   * Returns a raw map of configuration options defined in {@code .buckconfig} file and passed
   * through a {@code --config} command line option.
   */
  public abstract ImmutableMap<String, ImmutableMap<String, String>> getRawConfig();

  /** Returns a package identifier of the build file that is being parsed. */
  @Value.Derived
  public PackageIdentifier getPackageIdentifier() {
    return PackageIdentifier.create(
        RepositoryName.createFromValidStrippedName(getCellName()),
        PathFragment.createAlreadyNormalized(getBasePath().toString()));
  }

  /** Returns a cell name of the build file that is being parsed. */
  public abstract CanonicalCellName getCellName();

  public abstract ForwardRelativePath getBasePath();

  /** @return The event handler for reporting events during package parsing. */
  public abstract EventHandler getEventHandler();

  public static PackageContext of(
      Globber globber,
      Map<String, ? extends ImmutableMap<String, String>> rawConfig,
      CanonicalCellName cellName,
      ForwardRelativePath basePath,
      EventHandler eventHandler,
      Map<String, ? extends Object> implicitlyLoadedSymbols) {
    return ImmutablePackageContext.ofImpl(
        globber, rawConfig, cellName, basePath, eventHandler, implicitlyLoadedSymbols);
  }

  /** Gets objects that were implciitly loaded */
  public abstract ImmutableMap<String, Object> getImplicitlyLoadedSymbols();
}

@@ -719,183 +719,8 @@
 me;%0A
-import com.facebook.buck.core.model.label.PackageIdentifier;%0Aimport com.facebook.buck.core.model.label.PathFragment;%0Aimport com.facebook.buck.core.model.label.RepositoryName;%0A
 impo
@@ -771,16 +771,16 @@
 vePath;%0A
+
 import c
@@ -1008,43 +1008,8 @@
 Map;
-%0Aimport org.immutables.value.Value;
 %0A%0A/*
@@ -1403,24 +1403,24 @@
 tion.%0A   */%0A
+
   public abs
@@ -1497,337 +1497,8 @@
 );%0A%0A
-  /** Returns a package identifier of the build file that is being parsed. */%0A  @Value.Derived%0A  public PackageIdentifier getPackageIdentifier() %7B%0A    return PackageIdentifier.create(%0A        RepositoryName.createFromValidStrippedName(getCellName()),%0A        PathFragment.createAlreadyNormalized(getBasePath().toString()));%0A  %7D%0A%0A
   /*

Remove now unused PackageContext.getPackageIdentifier