/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Config file for defining DSL2 per module options and publishing paths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Available keys to override module options:
        ext.args   = Additional arguments appended to command in module.
        ext.args2  = Second set of arguments appended to command in module (multi-tool modules).
        ext.args3  = Third set of arguments appended to command in module (multi-tool modules).
        ext.prefix = File name prefix for output files.
----------------------------------------------------------------------------------------
*/

if (params.colabfold_server == 'webserver') {
    process {
        withName: 'COLABFOLD_BATCH' {
            ext.args = [
                params.use_gpu ? '' : '--cpu',
                params.use_amber ? '--amber' : '',
                params.use_templates ? '--templates' : '',
                params.host_url ? "--host-url ${params.host_url}" : ''
            ].join(' ').trim()
            publishDir = [
                path: { "${params.outdir}/${params.mode}/${params.colabfold_server}" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                pattern: '*.*'
            ]
        }
    }
}

if (params.colabfold_server == 'local') {
    process {
        withName: '.*:MMSEQS_.*' {
            publishDir = [
                enabled: false
            ]
        }
        withName: 'MMSEQS_CREATEINDEX' {
            ext.args = '--remove-tmp-files 1'
            publishDir = [
                enabled: false
            ]
        }
        withName: 'MMSEQS_COLABFOLDSEARCH' {
            ext.args = { params.db_load_mode ? "--db-load-mode ${params.db_load_mode}" : '' }
            publishDir = [
                enabled: false
            ]
        }
        withName: 'COLABFOLD_BATCH' {
            ext.args = [
                params.use_gpu       ? '' : '--cpu',
                params.use_amber     ? '--amber' : '',
                params.use_templates ? '--templates' : ''
            ].join(' ').trim()
            publishDir = [
                path: { "${params.outdir}/${params.mode}/${params.colabfold_server}" },
                mode: 'copy',
                saveAs: { filename -> filename.equals('versions.yml') ? null : filename },
                pattern: '*.*'
            ]
        }
    }
}
