import os

from xcp_d.utils.bids import collect_data, collect_run_data
from xcp_d.workflows.cifti import init_postprocess_cifti_wf
from xcp_d.utils.doc import download_example_data

fmri_dir = download_example_data()

layout, subj_data = collect_data(
    bids_dir=fmri_dir,
    input_type="fmriprep",
    participant_label="01",
    task="imagery",
    bids_validate=False,
    cifti=True,
)

bold_file = subj_data["bold"][0]
custom_confounds_folder = os.path.join(fmri_dir, "sub-01/func")
run_data = collect_run_data(
    layout=layout,
    input_type="fmriprep",
    bold_file=bold_file,
    cifti=True,
)

wf = init_postprocess_cifti_wf(
    bold_file=bold_file,
    fmri_dir=fmri_dir,
    bandpass_filter=True,
    high_pass=0.01,
    low_pass=0.08,
    bpf_order=2,
    motion_filter_type="notch",
    motion_filter_order=4,
    band_stop_min=12,
    band_stop_max=20,
    smoothing=6,
    head_radius=50.,
    params="27P",
    output_dir=".",
    custom_confounds_folder=custom_confounds_folder,
    dummy_scans=2,
    fd_thresh=0.3,
    despike=True,
    dcan_qc=True,
    run_data=run_data,
    t1w_available=True,
    t2w_available=True,
    n_runs=1,
    min_coverage=0.5,
    exact_scans=[],
    random_seed=None,
    omp_nthreads=1,
    layout=layout,
    name="cifti_postprocess_wf",
)
wf.inputs.inputnode.t1w = subj_data["t1w"]