info:
  name: Richiedente - Importo ripartizione da Proposta
  type: http
  seq: 3

http:
  method: POST
  url: "{{elixFormsApiUrl}}/eftl/process/v1"
  headers:
    - name: x-requested-with
      value: XMLHttpRequest
    - name: x-api-key
      value: "{{elixFormsWsAuthenticationToken}}"
    - name: x-ef-request-id
      value: "31555"
  body:
    type: json
    data: |-
      {
        "userDocument": "{{elixBase64EftlDocument}}", // see the pre-request script
        "userContext": {
          "lang": "IT",
          "crlf": "\r\n"
        }
      }
  auth: inherit

runtime:
  scripts:
    - type: before-request
      code: |-
        const { prepareEftlDocument } = require("./elixFormsJs.js")
        // Copy-pasta your EFTL document below inside the template literals (`)
        prepareEftlDocument(String.raw`
        [EFTL][HEADER name="trimDocument" value="true" type="boolean" /]
        [VAR name="codiceFiscaleRichiedente" type="string"][TAG]GETVALUEBYTAG,RICHIEDENTE_CODFIS,REQUEST,IUQOID[/TAG][/VAR]
        [VAR name="datiRipartizioniIterable" type="iterable"][SPLIT regex="##"][TAG]GETVALUEBYTAG,RIPARTIZIONE_DATI_COMPLETI,REQUEST,IUQOID,CONCAT,##[/TAG][/SPLIT][/VAR]

        [VAR name="item2" type="number"][% item2 = 1; %][/VAR]
        [VAR name="item5" type="number"][% item5 = 4; %][/VAR]

        [VAR name="importoRichiedente" type="number"][% importoRichiedente = 0; %][/VAR]

        [FOR varname="riga" iterable="datiRipartizioniIterable"]
          [VAR name="rigaiIterable" type="iterable"][SPLIT regex=";;"][VALUE_OF varname="riga" /][/SPLIT][/VAR]
          [VAR name="codiceFiscale" type="string"][VALUE_OF varname="rigaiIterable" index="item2" /][/VAR]
          [VAR name="importo" type="number"][VALUE_OF varname="rigaiIterable" index="item5" /][/VAR]
          [IF]
            [CONDITION][% codiceFiscale == codiceFiscaleRichiedente %][/CONDITION]
            [THEN][% importoRichiedente = importo; %][/THEN]
          [/IF]
        [/FOR]

        [FORMAT type="number" pattern="0.00"][% importoRichiedente %][/FORMAT]
        [/EFTL]
        `);

settings:
  encodeUrl: true
  timeout: 0
  followRedirects: true
  maxRedirects: 5
  forwardAuthorizationHeader: true

docs: |-
  SchemaId 709
  Campo COL0118
