from __future__ import annotations

import pytest

from m3m_disease.dataset import assign_splits, matrix_from_records, split_by_group
from m3m_disease.demo import generate_records, generate_synthetic_fixture
from m3m_disease.model import fit_logistic


@pytest.fixture(scope="session")
def trained_bundle(tmp_path_factory):
    root = tmp_path_factory.mktemp("m3m-disease-bundle")
    manifests = generate_synthetic_fixture(root / "fixture", seed=20260804)
    records = generate_records(manifests)
    assignments = split_by_group(records, seed=20260804)
    assigned = assign_splits(records, assignments)
    matrix, labels, _ = matrix_from_records(assigned, split="train")
    model = fit_logistic(matrix, labels)
    return {
        "root": root,
        "manifests": manifests,
        "records": records,
        "assigned": assigned,
        "model": model,
    }
