# -*- coding: utf-8 -*-

"""Generate the Resilient customizations required for {{package}}"""

from __future__ import print_function
from resilient_circuits.util import *

def codegen_reload_data():
    """Parameters to codegen used to generate the {{package}} package"""
    reload_params = {"package": u"{{package}}",
                   {%if incident_fields|length > 0 %} "incident_fields": [u"{{incident_fields.values()|map(attribute="name")|sort|join('", u"')}}"], {%else%} "incident_fields": [], {%endif%}
                   {%if action_fields|length > 0 %} "action_fields": [u"{{action_fields.values()|map(attribute="name")|sort|join('", u"')}}"], {%else%} "action_fields": [], {%endif%}
                   {%if function_params|length > 0 %} "function_params": [u"{{function_params.values()|map(attribute="name")|sort|join('", u"')}}"], {%else%} "functions_params": [], {%endif%}
                   {%if datatables.keys()%} "datatables": [u"{{datatables.keys()|sort|join('", u"')}}"], {%else%} "datatables": [], {%endif%}
                   {%if message_destinations.keys()%} "message_destinations": [u"{{message_destinations.keys()|sort|join('", u"')}}"], {%else%} "message_destinations": [], {%endif%}
                   {%if functions.keys()%} "functions": [u"{{functions.keys()|sort|join('", u"')}}"], {%else%} "functions": [], {%endif%}
                   {%if phases.keys()%} "phases": [u"{{phases.keys()|sort|join('", u"')}}"], {%else%} "phases": [], {%endif%}
                   {%if automatic_tasks.keys()%} "automatic_tasks": [u"{{automatic_tasks.keys()|sort|join('", u"')}}"], {%else%} "automatic_tasks": [], {%endif%}
                   {%if scripts.keys()%} "scripts": [u"{{scripts.keys()|sort|join('", u"')}}"], {%else%} "scripts": [], {%endif%}
                   {%if workflows.keys()%} "workflows": [u"{{workflows.keys()|sort|join('", u"')}}"], {%else%} "workflows": [],{%endif%}
                   {%if actions.keys()%} "actions": [u"{{actions.keys()|sort|join('", u"')}}"], {%else%} "actions": [],{%endif%}
                   {%if incident_artifact_types.keys()%} "incident_artifact_types": [u"{{incident_artifact_types.keys()|sort|join('", u"')}}"] {%else%} "incident_artifact_types": [] {%endif%}
                    }
    return reload_params


def customization_data(client=None):
    """Produce any customization definitions (types, fields, message destinations, etc)
       that should be installed by `resilient-circuits customize`
    """

    # This import data contains:
{%if incident_fields|length > 0 %}    #   Incident fields:
    #     {{incident_fields.values()|map(attribute="name")|sort|join("\n    #     ")}}
{%endif%}{%if action_fields|length > 0 %}    #   Action fields:
    #     {{action_fields.values()|map(attribute="name")|sort|join("\n    #     ")}}
{%endif%}{%if function_params|length > 0 %}    #   Function inputs:
    #     {{function_params.values()|map(attribute="name")|sort|join("\n    #     ")}}
{%endif%}{%if datatables.keys()%}    #   DataTables:
    #     {{datatables.keys()|sort|join("\n    #     ")}}
{%endif%}{%if message_destinations.keys()%}    #   Message Destinations:
    #     {{message_destinations.keys()|sort|join("\n    #     ")}}
{%endif%}{%if functions.keys()%}    #   Functions:
    #     {{functions.keys()|sort|join("\n    #     ")}}
{%endif%}{%if phases.keys()%}    #   Phases:
    #     {{phases.keys()|sort|join("\n    #     ")}}
{%endif%}{%if automatic_tasks.keys()%}    #   Tasks:
    #     {{automatic_tasks.keys()|sort|join("\n    #     ")}}
{%endif%}{%if scripts.keys()%}    #   Scripts:
    #     {{scripts.keys()|sort|join("\n    #     ")}}
{%endif%}{%if workflows.keys()%}    #   Workflows:
    #     {{workflows.keys()|sort|join("\n    #     ")}}
{%endif%}{%if actions.keys()%}    #   Rules:
    #     {{actions.keys()|sort|join("\n    #     ")}}
{%endif%}{%if incident_artifact_types.keys()%}    #   Incident artifact types:
    #     {{incident_artifact_types.keys()|sort|join("\n    #     ")}}
{%endif%}

    yield ImportDefinition(u"""
{{export_data|base64}}"""
    )
