"""profile_data handler — compute per-column statistics and correlations."""
from typing import Optional

import polars as pl

from ..data_profiler import profile_dataset as _profile_dataset
from ._helpers import _resolve_dataset


async def _handle_profile_data(
    dataset_id: str,
    sample_size: int = 1000,
    columns: Optional[list[str]] = None,
) -> dict:
    """Profile dataset columns and correlations."""
    entry, err = _resolve_dataset(dataset_id)
    if err:
        return err

    lf: pl.LazyFrame = entry['lazyframe']
    profile = _profile_dataset(lf, sample_size=sample_size, columns=columns)
    return profile
