/**
 *
 * This file is auto-generated. Do not edit manually: changes may be erased.
 * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. 
 * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
 * Aqua version: 0.1.9-163
 *
 */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';



export async function echo_greeting_par_greet(client: FluenceClient, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {greet:boolean;node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
         (call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
        )
        (call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
       )
       (call -relay- ("op" "noop") [])
      )
      (xor
       (seq
        (call -relay- ("op" "noop") [])
        (call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
       )
       (seq
        (call -relay- ("op" "noop") [])
        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
       )
      )
     )
     (call -relay- ("op" "noop") [])
    )
    (fold echo_results result
     (seq
      (fold greeting_services greeting_service
       (seq
        (seq
         (par
          (seq
           (seq
            (xor
             (call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
             (seq
              (call -relay- ("op" "noop") [])
              (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
             )
            )
            (call -relay- ("op" "noop") [])
           )
           (call %init_peer_id% ("op" "noop") [])
          )
          (null)
         )
         (call -relay- ("op" "noop") [])
        )
        (next greeting_service)
       )
      )
      (next result)
     )
    )
   )
   (call %init_peer_id% ("op" "identity") [$res.$.[5]!])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'echo_service', () => {return echo_service;});
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_par_greet');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      


export async function echo_greeting_par(client: FluenceClient, greet: boolean, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (seq
          (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
          (call %init_peer_id% ("getDataSrv" "greet") [] greet)
         )
         (call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
        )
        (call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
       )
       (call -relay- ("op" "noop") [])
      )
      (xor
       (seq
        (call -relay- ("op" "noop") [])
        (call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
       )
       (seq
        (call -relay- ("op" "noop") [])
        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
       )
      )
     )
     (call -relay- ("op" "noop") [])
    )
    (fold echo_results result
     (seq
      (fold greeting_services greeting_service
       (seq
        (seq
         (par
          (seq
           (seq
            (xor
             (call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
             (seq
              (call -relay- ("op" "noop") [])
              (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
             )
            )
            (call -relay- ("op" "noop") [])
           )
           (call %init_peer_id% ("op" "noop") [])
          )
          (null)
         )
         (call -relay- ("op" "noop") [])
        )
        (next greeting_service)
       )
      )
      (next result)
     )
    )
   )
   (call %init_peer_id% ("op" "identity") [$res.$.[5]!])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'greet', () => {return greet;});
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_par');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      


export async function echo_greeting_par_inverse(client: FluenceClient, greet: boolean, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (seq
          (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
          (call %init_peer_id% ("getDataSrv" "greet") [] greet)
         )
         (call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
        )
        (call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
       )
       (call -relay- ("op" "noop") [])
      )
      (xor
       (seq
        (call -relay- ("op" "noop") [])
        (call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
       )
       (seq
        (call -relay- ("op" "noop") [])
        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
       )
      )
     )
     (call -relay- ("op" "noop") [])
    )
    (fold greeting_services greeting_service
     (seq
      (seq
       (par
        (seq
         (seq
          (xor
           (fold echo_results result
            (seq
             (call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
             (next result)
            )
           )
           (seq
            (call -relay- ("op" "noop") [])
            (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
           )
          )
          (call -relay- ("op" "noop") [])
         )
         (call %init_peer_id% ("op" "noop") [])
        )
        (null)
       )
       (call -relay- ("op" "noop") [])
      )
      (next greeting_service)
     )
    )
   )
   (call %init_peer_id% ("op" "identity") [$res.$.[3]!])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'greet', () => {return greet;});
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_par_inverse');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      


export async function echo_greeting_seq(client: FluenceClient, names: string[], greet: boolean, node: string, echo_service_id: string, greeting_service_id: string, config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (seq
          (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
          (call %init_peer_id% ("getDataSrv" "names") [] names)
         )
         (call %init_peer_id% ("getDataSrv" "greet") [] greet)
        )
        (call %init_peer_id% ("getDataSrv" "node") [] node)
       )
       (call %init_peer_id% ("getDataSrv" "echo_service_id") [] echo_service_id)
      )
      (call %init_peer_id% ("getDataSrv" "greeting_service_id") [] greeting_service_id)
     )
     (call -relay- ("op" "noop") [])
    )
    (xor
     (seq
      (seq
       (call -relay- ("op" "noop") [])
       (call node (echo_service_id "echo") [names] echo_names)
      )
      (fold echo_names result
       (seq
        (call node (greeting_service_id "greeting") [result.$.echo! greet] $res)
        (next result)
       )
      )
     )
     (seq
      (call -relay- ("op" "noop") [])
      (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
     )
    )
   )
   (call -relay- ("op" "noop") [])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'names', () => {return names;});
h.on('getDataSrv', 'greet', () => {return greet;});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'echo_service_id', () => {return echo_service_id;});
h.on('getDataSrv', 'greeting_service_id', () => {return greeting_service_id;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_seq');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      


export async function echo_greeting_seq_2(client: FluenceClient, names: string[], greet: boolean, echo_topo: {node:string;service_id:string}, greeting_topo: {node:string;service_id:string}, config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (seq
          (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
          (call %init_peer_id% ("getDataSrv" "names") [] names)
         )
         (call %init_peer_id% ("getDataSrv" "greet") [] greet)
        )
        (call %init_peer_id% ("getDataSrv" "echo_topo") [] echo_topo)
       )
       (call %init_peer_id% ("getDataSrv" "greeting_topo") [] greeting_topo)
      )
      (call -relay- ("op" "noop") [])
     )
     (xor
      (seq
       (call -relay- ("op" "noop") [])
       (call echo_topo.$.node! (echo_topo.$.service_id! "echo") [names] echo_names)
      )
      (seq
       (seq
        (call -relay- ("op" "noop") [])
        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
       )
       (call -relay- ("op" "noop") [])
      )
     )
    )
    (xor
     (fold echo_names result
      (seq
       (call greeting_topo.$.node! (greeting_topo.$.service_id! "greeting") [result.$.echo! greet] $res)
       (next result)
      )
     )
     (seq
      (call -relay- ("op" "noop") [])
      (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
     )
    )
   )
   (call -relay- ("op" "noop") [])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'names', () => {return names;});
h.on('getDataSrv', 'greet', () => {return greet;});
h.on('getDataSrv', 'echo_topo', () => {return echo_topo;});
h.on('getDataSrv', 'greeting_topo', () => {return greeting_topo;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_seq_2');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      


export async function echo_greeting_par_inverse_greet(client: FluenceClient, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {greet:boolean;node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
    let request: RequestFlow;
    const promise = new Promise<string[]>((resolve, reject) => {
        const r = new RequestFlowBuilder()
            .disableInjections()
            .withRawScript(
                `
(xor
 (seq
  (seq
   (seq
    (seq
     (seq
      (seq
       (seq
        (seq
         (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
         (call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
        )
        (call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
       )
       (call -relay- ("op" "noop") [])
      )
      (xor
       (seq
        (call -relay- ("op" "noop") [])
        (call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
       )
       (seq
        (call -relay- ("op" "noop") [])
        (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
       )
      )
     )
     (call -relay- ("op" "noop") [])
    )
    (fold greeting_services greeting_service
     (seq
      (seq
       (par
        (seq
         (seq
          (xor
           (fold echo_results result
            (seq
             (call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
             (next result)
            )
           )
           (seq
            (call -relay- ("op" "noop") [])
            (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
           )
          )
          (call -relay- ("op" "noop") [])
         )
         (call %init_peer_id% ("op" "noop") [])
        )
        (null)
       )
       (call -relay- ("op" "noop") [])
      )
      (next greeting_service)
     )
    )
   )
   (call %init_peer_id% ("op" "identity") [$res.$.[3]!])
  )
  (xor
   (call %init_peer_id% ("callbackSrv" "response") [$res])
   (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
  )
 )
 (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)

            `,
            )
            .configHandler((h) => {
                h.on('getDataSrv', '-relay-', () => {
                    return client.relayPeerId!;
                });
                h.on('getDataSrv', 'echo_service', () => {return echo_service;});
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
                h.onEvent('callbackSrv', 'response', (args) => {
  const [res] = args;
  resolve(res);
});

                h.onEvent('errorHandlingSrv', 'error', (args) => {
                    // assuming error is the single argument
                    const [err] = args;
                    reject(err);
                });
            })
            .handleScriptError(reject)
            .handleTimeout(() => {
                reject('Request timed out for echo_greeting_par_inverse_greet');
            })
        if(config?.ttl) {
            r.withTTL(config.ttl)
        }
        request = r.build();
    });
    await client.initiateFlow(request!);
    return promise;
}
      