/*
 * Copyright 2003-2016 JetBrains s.r.o.
 *
 * 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 jetbrains.mps.extapi.persistence.datasource;

import jetbrains.mps.extapi.persistence.SourceRoot;
import jetbrains.mps.util.annotation.ToRemove;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.mps.openapi.model.SModelName;
import org.jetbrains.mps.openapi.persistence.DataSource;
import org.jetbrains.mps.openapi.persistence.ModelRoot;
import org.jetbrains.mps.openapi.persistence.datasource.DataSourceType;

/**
 * Interface for creating a new {@link DataSource} from a given model name.
 *
 * It is somehow vital to extract the strategy defining the location (data source) of the new model
 * when the name is given. One could choose the place to store a model in various ways depending on
 * the structure of the model name (for example if we are java-minded we might store a model with a name
 * 'my.favourite.package.modelName' as a folder cascade: 'my/favourite/package/modelName.mps').
 *
 * It is used when we create a new model from anywhere (IDE, tests, etc.).
 *
 * @see DataSourceFactoryFromURL
 * @author apyshkin
 * @since 3.5
 */
public interface DataSourceFactoryFromName {

  /**
   * @return the type of the created data sources
   */
  @NotNull DataSourceType getType();

  /**
   * This is invoked in order to create a new model from scratch given only its name.
   * For instance it might be useful if we want to put a model accordingly to it's fq name
   * or if we want to provide some specific extension of the new model file (if we are based on file system).
   * @param modelName new model name
   * @param sourceRoot source root which will host the newly created model
   *
   * @param modelRoot model root which is the host of the given source root.
   *                  It will be dropped when the bundled data source constructors do not need a model root
   * @return new data source which points to location generated by this method from the model name
   *
   */
  @NotNull DataSource create(@NotNull SModelName modelName,
                             @NotNull SourceRoot sourceRoot,

                             @ToRemove(version = 0)
                             @Nullable ModelRoot modelRoot);
}
