package alien4cloud.model.components;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import alien4cloud.tosca.ToscaUtils;
import alien4cloud.tosca.normative.ToscaFunctionConstants;
import alien4cloud.ui.form.annotation.FormProperties;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * A TOSCA function to be used as the value for a property (or operation parameter).
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@FormProperties({ "function", "parameters" })
public class FunctionPropertyValue extends AbstractPropertyValue {
    private String function;

    private List<String> parameters;

    /** Get the modelable entity's (node or relationship template) name related to the function, represented by the first parameter. */
    @JsonIgnore
    public String getTemplateName() {
        return parameters.get(0);
    }

    /** get the name of the property or attribute or the output we want to retrieve, represented by the last parameter in the list */
    @JsonIgnore
    public String getElementNameToFetch() {
        return parameters.get(parameters.size() - 1);
    }

    /** Get, if provided, the capability/requirement name within the template which contains the prop or attr to retrieve */
    @JsonIgnore
    public String getCapabilityOrRequirementName() {
        if (function != null && parameters.size() > 2) {
            switch (function) {
            case ToscaFunctionConstants.GET_PROPERTY:
            case ToscaFunctionConstants.GET_ATTRIBUTE:
            case ToscaFunctionConstants.GET_INPUT:
                return parameters.get(1);
            default:
                return null;
            }
        }
        return null;
    }

    /** Get, in case of get_operation_output, the name of the interface related to the function, represented by the second parameter in the list */
    @JsonIgnore
    public String getInterfaceName() {
        if (function != null) {
            switch (function) {
            case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
                return parameters.size() > 2 ? ToscaUtils.getProperInterfaceName(parameters.get(1)) : null;
            default:
                return null;
            }
        }
        return null;
    }

    /** Get, in case of get_operation_output, the name of the operation related to the function, represented by the third parameter in the list */
    @JsonIgnore
    public String getOperationName() {
        if (function != null) {
            switch (function) {
            case ToscaFunctionConstants.GET_OPERATION_OUTPUT:
                return parameters.size() > 3 ? parameters.get(2) : null;
            default:
                return null;
            }
        }
        return null;
    }
}
@@ -67,111 +67,53 @@
 ort 
-lombok.AllArgsConstructor;%0Aimport lombok.Getter;%0Aimport lombok.NoArgsConstructor;%0Aimport lombok.Setter;
+com.fasterxml.jackson.annotation.JsonIgnore;%0A
 %0Aimp
@@ -263,59 +263,117 @@
 es;%0A
-%0A
 import 
-com.fasterxml.jackson.annotation.JsonIgnore
+lombok.AllArgsConstructor;%0Aimport lombok.Getter;%0Aimport lombok.NoArgsConstructor;%0Aimport lombok.Setter
 ;%0A%0A/
@@ -536,17 +536,16 @@
 erties(%7B
- 
 %22functio
@@ -560,17 +560,16 @@
 ameters%22
- 
 %7D)%0Apubli
@@ -701,24 +701,31 @@
 rs;%0A%0A    /**
+%0A     *
  Get the mod
@@ -837,16 +837,21 @@
 rameter.
+%0A    
  */%0A    
@@ -945,18 +945,153 @@
  %7D%0A%0A    
-/*
+@JsonIgnore%0A    public String setTemplateName(String templateName) %7B%0A        return parameters.set(0, templateName);%0A    %7D%0A%0A    /**%0A     
 * get th
@@ -1198,32 +1198,37 @@
 eter in the list
+%0A    
  */%0A    @JsonIgn
@@ -1332,34 +1332,181 @@
  1);%0A    %7D%0A%0A    
-/*
+@JsonIgnore%0A    public String setElementNameToFetch(String value) %7B%0A        return parameters.set(parameters.size() - 1, value);%0A    %7D%0A%0A    /**%0A     
 * Get, if provid
@@ -1604,16 +1604,21 @@
 retrieve
+%0A    
  */%0A    
@@ -1775,32 +1775,36 @@
 ) %7B%0A            
+    
 case ToscaFuncti
@@ -1829,16 +1829,20 @@
 OPERTY:%0A
+    
         
@@ -1892,32 +1892,36 @@
 TE:%0A            
+    
 case ToscaFuncti
@@ -1951,32 +1951,36 @@
                 
+    
 return parameter
@@ -1985,24 +1985,28 @@
 ers.get(1);%0A
+    
             
@@ -2022,32 +2022,36 @@
                 
+    
 return null;%0A   
@@ -2098,32 +2098,39 @@
 ;%0A    %7D%0A%0A    /**
+%0A     *
  Get, in case of
@@ -2242,32 +2242,37 @@
 eter in the list
+%0A    
  */%0A    @JsonIgn
@@ -2382,32 +2382,36 @@
 ) %7B%0A            
+    
 case ToscaFuncti
@@ -2436,32 +2436,36 @@
 ERATION_OUTPUT:%0A
+    
                 
@@ -2560,32 +2560,36 @@
 ll;%0A            
+    
 default:%0A       
@@ -2573,32 +2573,36 @@
        default:%0A
+    
                 
@@ -2673,16 +2673,23 @@
 %0A    /**
+%0A     *
  Get, in
@@ -2816,16 +2816,21 @@
 the list
+%0A    
  */%0A    
@@ -2936,32 +2936,36 @@
 ch (function) %7B%0A
+    
             case
@@ -3018,32 +3018,36 @@
                 
+    
 return parameter
@@ -3091,32 +3091,36 @@
 ll;%0A            
+    
 default:%0A       
@@ -3104,32 +3104,36 @@
        default:%0A
+    
                 

Add setter utility method for FunctionPropertyValue