<#ftl output_format="JSON">
<#-- newRecordViewInterface: The macro for generating view and template metadata for a new Record View Interface -->
<#macro newRecordViewInterface request recipeObjectId uuid name description ruleFolderUuid triggers="">
<#assign textResolver = request.getTextResolver()>
{
    <#-- recipe section -->
    "version": 2,
    "objectType": "INTERFACE",
    "replaceable": false,
    "recipeObjectId": "${recipeObjectId}",
    "templateForCreate": "createRecordViewInterface.ftlx",
    "selectedObjectIndex": 0,
    "isVisible": true,
    <#if triggers?has_content>
    "triggers": ${triggers},
    </#if>

    <#-- the set of new and reused objects -->
    "objects": [
         {
            "objectStatus": "NEW",
            "templateObjectId": "${recipeObjectId}-0",
            "objectIndex": 0,

             <#-- bindings section -->
            "uuid": "${uuid}",
            "versionUuids": ["${request.generateUuid("INTERFACE_VERSION")}"],
            "parentUuid": "${ruleFolderUuid}",
            "baseRecordUuid": "${request.getTargetObject().uuid}",
            "relationships": [
            <#list request.getTargetObject().relationships as relationship>
              {
                "uuid": "${relationship.uuid}",
                <#if relationship.targetRecordTypeUuid??>
                "targetRecordTypeUuid": "${relationship.targetRecordTypeUuid}",
                </#if>
                <#if relationship.targetRecordTypeFieldUuid??>
                "targetRecordTypeFieldUuid": "${relationship.targetRecordTypeFieldUuid}",
                </#if>
                <#if relationship.targetRecordTypeFieldUuid??>
                "sourceRecordTypeFieldUuid": "${relationship.sourceRecordTypeFieldUuid}",
                </#if>
                "name": "${relationship.nameWithoutAppPrefix?json_string}",
                "expressionableName": "${textResolver.format(relationship.name, "CAMEL_CASE", "relatedRecord")?json_string}",
                "relationshipType": "${relationship.relationshipType}",
                <#if relationship.gridColumnsExpression??>
                "gridColumnsExpression": "${relationship.gridColumnsExpression?json_string}",
                </#if>
                "fields": [
                <#assign nonPKFields=relationship.fields?filter(f->!f.properties.isPrimaryKey)>
                <#list nonPKFields as field>
                    {
                        "name": "${field.name?json_string}",
                        "friendlyName": "${field.properties.friendlyName}",
                        "type":  "${field.type.type}",
                        "uuid": "${field.uuid}"
                    <#if field?has_next>
                    },
                    <#else>
                    }
                    </#if>
                </#list>
                ]
              <#if relationship?has_next>
              },
              <#else>
              }
              </#if>
            </#list>
            ],

            <#-- i18n section -->
            "name": "${name?json_string}",
            "description": "${description?json_string}",
            "i18n": {
               "booleanYes": "${request.getTextWithKey("recordViewTemplateRecipe.object.interface.booleanField.yes")?json_string}",
               "booleanNo": "${request.getTextWithKey("recordViewTemplateRecipe.object.interface.booleanField.no")?json_string}"
            }
         }
    ]
}
</#macro>