from typing import Any, List, Optional, Union

from ..report_conditions import CustomReportConditions
from ..report_element import CustomReportElement
from ..report_named_resource import CustomReportNamedResource


class ExcludeDataPreparer(CustomReportElement):
    """Excludes rows from a resource that match a condition."""

    def __init__(
        self,
        field_name: str,
        resource: Union[CustomReportNamedResource, Any],
        excluded_resource: Optional[Union[CustomReportNamedResource, Any]] = None,
        conditions: Optional[List[CustomReportConditions]] = None,
    ):
        """Creates an ExcludeDataPreparer.

        Args:
            field_name: Field used to match rows for exclusion.
            resource: Source resource to filter.
            excluded_resource: Optional resource containing the values to exclude.
            conditions: Export-format conditions that control when this preparer is applied.
        """
        super().__init__(name="exclude_data", conditions=conditions)
        self.add_param("field_name", field_name)
        self.add_param("resource", resource)
        self.add_param("excluded_resource", excluded_resource)
