from typing import Any, List, Optional, Union

from ..report_conditions import CustomReportConditions
from ..report_element import CustomReportElement
from ..report_named_resource import CustomReportNamedResource
from ..report_title import ReportTitle
from ..utils import add_param


class SheetTableRenderer(CustomReportElement):
    """Renders data as a table in a dedicated sheet (XLS exports)."""

    def __init__(
        self,
        columns: Union[CustomReportNamedResource, Any],
        data: Union[CustomReportNamedResource, Any],
        style: Optional[str] = None,
        title: Optional[ReportTitle] = None,
        subtitle: Optional[ReportTitle] = None,
        limit: Optional[int] = None,
        sheet_name: Optional[str] = None,
        sheet_index_offset: Optional[int] = None,
        auto_fit_width: Optional[bool] = None,
        auto_filter: Optional[bool] = None,
        sheet_protection: Optional[bool] = None,
        conditions: Optional[List[CustomReportConditions]] = None,
        spacing: Optional[int] = None,
    ):
        """Creates a SheetTableRenderer.

        Args:
            columns: Resource that defines the column configuration.
            data: Resource that provides the row data.
            style: Optional style identifier.
            title: Optional table title.
            subtitle: Optional table subtitle.
            limit: Maximum number of rows to render.
            sheet_name: Name of the target sheet.
            sheet_index_offset: Offset applied to the sheet index.
            auto_fit_width: Whether to auto-fit column widths.
            auto_filter: Whether to enable auto-filter on headers.
            sheet_protection: Whether to protect the sheet from editing.
            conditions: Export-format conditions that control when this renderer is applied.
            spacing: Vertical spacing before this renderer.
        """
        params = {}
        add_param(params, "columns", columns)
        add_param(params, "data", data)
        add_param(params, "style", style)
        add_param(params, "title", title)
        add_param(params, "subtitle", subtitle)
        add_param(params, "limit", limit)
        add_param(params, "sheet_name", sheet_name)
        add_param(params, "sheet_index_offset", sheet_index_offset)
        add_param(params, "auto_fit_width", auto_fit_width)
        add_param(params, "auto_filter", auto_filter)
        add_param(params, "sheet_protection", sheet_protection)
        super().__init__(name="sheet_table", params=params, conditions=conditions, spacing=spacing)
