from typing import Any, List, Optional, Union

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


class AddFormatFieldPreparer(CustomReportElement):
    """Adds a computed field formatted from multiple source fields."""

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

        Args:
            field_name: Name of the new computed field.
            fields: Source fields used to build the formatted value.
            format: Format string applied to the source fields.
            resource: Resource that provides the source data.
            conditions: Export-format conditions that control when this preparer is applied.
        """
        super().__init__(name="add_format_field", conditions=conditions)
        self.add_param("field_name", field_name)
        self.add_param("fields", fields)
        self.add_param("format", format)
        self.add_param("resource", resource)
