/*
 * Copyright 2014 defrac inc.
 *
 * 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 defrac.intellij.run;

import com.intellij.debugger.impl.GenericDebuggerRunner;
import com.intellij.debugger.impl.GenericDebuggerRunnerSettings;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.ConfigurationInfoProvider;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.openapi.options.SettingsEditor;
import defrac.intellij.facet.DefracFacet;
import org.jetbrains.annotations.NotNull;

/**
 */
public final class DefracDebugRunner extends GenericDebuggerRunner {
  @NotNull
  @Override
  public String getRunnerId() {
    return "DefracDebugRunner";
  }

  @Override
  public GenericDebuggerRunnerSettings createConfigurationData(final ConfigurationInfoProvider settingsProvider) {
    // no overriding
    return null;
  }

  @Override
  public SettingsEditor<GenericDebuggerRunnerSettings> getSettingsEditor(final Executor executor, final RunConfiguration configuration) {
    // no settings needed
    return null;
  }

  @Override
  public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) {
    if(profile instanceof DefracRunConfiguration) {
      final DefracRunConfiguration configuration = (DefracRunConfiguration)profile;
      final DefracFacet facet = configuration.getFacet();

      return super.canRun(executorId, profile) && facet != null && !facet.getPlatform().isAndroid();
    }
    return false;
  }
}
