package io.cloudsoft.terraform;

import java.util.Map;

import org.apache.brooklyn.api.entity.ImplementedBy;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.annotation.Effector;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.effector.MethodEffector;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.entity.software.base.SoftwareProcess;
import org.apache.brooklyn.util.core.flags.SetFromFlag;

@ImplementedBy(TerraformConfigurationImpl.class)
public interface TerraformConfiguration extends SoftwareProcess {

    @SetFromFlag("version")
    ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "0.6.3");

    @SetFromFlag("downloadUrl")
    BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new StringAttributeSensorAndConfigKey(
            Attributes.DOWNLOAD_URL, "https://dl.bintray.com/mitchellh/terraform/terraform_${version}_darwin_amd64.zip");

    @SetFromFlag("configurationContents")
    ConfigKey<String> CONFIGURATION_CONTENTS = ConfigKeys.newStringConfigKey(
            "configuration.contents",
            "Contents of the configuration file that will be applied by Terraform.",
            "");

    @SetFromFlag("configurationUrl")
    ConfigKey<String> CONFIGURATION_URL = ConfigKeys.newStringConfigKey(
            "configuration.url",
            "URL of the configuration file that will be applied by Terraform.",
            "");

    AttributeSensor<Boolean> CONFIGURATION_IS_APPLIED = Sensors.newBooleanSensor("configuration.isApplied",
            "Whether the supplied Terraform configuration has been successfully applied.");

    AttributeSensor<String> SHOW = Sensors.newStringSensor("show",
            "The contents of the Terraform show command which provides a human-readable view of the state of the configuration.");

    AttributeSensor<String> PLAN = Sensors.newStringSensor("plan",
            "The contents of the Terraform plan command which specifies exactly what actions will be taken upon applying the configuration.");

    @SuppressWarnings({ "rawtypes", "unchecked" })
    AttributeSensor<Map<String, Object>> STATE = new BasicAttributeSensor(Map.class, "state",
            "A map constructed from the state file on disk which contains the state of all managed infrastructure.");

    MethodEffector<Void> APPLY = new MethodEffector<Void>(TerraformConfiguration.class, "apply");

    @Effector(description="Performs the Terraform apply command which will create all of the infrastructure specified by the configuration.")
    void apply();

    @Effector(description="Performs the Terraform destroy command which will destroy all of the infrastructure that has been previously created by the configuration.")
    void destroy();
}

@@ -1356,33 +1356,35 @@
   @SetFromFlag(%22
-c
+tfC
 onfigurationCont
@@ -1473,32 +1473,35 @@
 y(%0A            %22
+tf.
 configuration.co
@@ -1630,17 +1630,19 @@
 omFlag(%22
-c
+tfC
 onfigura
@@ -1737,16 +1737,19 @@
        %22
+tf.
 configur
@@ -1940,16 +1940,19 @@
 Sensor(%22
+tf.
 configur
@@ -2122,16 +2122,19 @@
 Sensor(%22
+tf.
 show%22,%0A 
@@ -2324,16 +2324,19 @@
 Sensor(%22
+tf.
 plan%22,%0A 
@@ -2615,16 +2615,19 @@
 class, %22
+tf.
 state%22,%0A
@@ -2741,24 +2741,24 @@
 ucture.%22);%0A%0A
-
     MethodEf
@@ -2840,24 +2840,127 @@
  %22apply%22);%0A%0A
+    MethodEffector%3CVoid%3E DESTROY = new MethodEffector%3CVoid%3E(TerraformConfiguration.class, %22destroy%22);%0A%0A
     @Effecto

Prepend 'tf' to sensor names