# Source code for matchtable.matchitem

    from typing import Any, Literal, NotRequired, Self, TypedDict, cast
    from uuid import uuid4

    from .column import ColumnType
    from .i18n import I18nWord, UidRef

    Link = Any

    MatchItemType = Literal["Added", "Deleted", "Unchanged", "Changed"]

    class IdentificationCriteria(TypedDict):
        type: ColumnType
        threshold: float

    class MatchItem(TypedDict):
        name: str | UidRef
        type: NotRequired[MatchItemType]
        sourceItemId: str | None
        sourceItemName: str | UidRef | None
        destinationItemId: str | None
        destinationItemName: str | UidRef | None
        identificationCriteria: NotRequired[dict[str, IdentificationCriteria]]

    class MatchItemBuilder:
        """Create a match item."""

        def __init__(self, dst_id: str | Link | None, src_id: str | Link | None):
            self.id = str(uuid4())
            self.name: str | UidRef
            self.destination_id = dst_id
            self.destination_name: str | UidRef | None = None
            self.source_id = src_id
            self.source_name: str | UidRef | None = None
            self.properties: dict[str, Any] = {}
            self.type: MatchItemType | None = None

        def set_name(self, name: str) -> Self:
            """Set the name to the item."""
            self.name = name
            return self

        def set_name_i18n(self, name: I18nWord) -> Self:
            """Set the i18n word as the name of the item."""
            self.name = UidRef(uid_ref=name["key"], uid_type="i18n")
            return self

        def set_destination_name(self, name: str) -> Self:
            """Set the name of the destination data."""
            self.destination_name = name
            return self

        def set_destination_name_i18n(self, name: I18nWord) -> Self:
            """Set the i18n word as the name of the destination data."""
            self.destination_name = UidRef(uid_ref=name["key"], uid_type="i18n")
            return self

        def set_source_name(self, name: str) -> Self:
            """Set the name of the source data."""
            self.source_name = name
            return self

        def set_source_name_i18n(self, name: I18nWord) -> Self:
            """Set the i18n word as the name of the source data."""
            self.source_name = UidRef(uid_ref=name["key"], uid_type="i18n")
            return self

        def set_type(self, item_type: MatchItemType) -> Self:
            """Set the type of the item."""
            self.type = item_type
            return self

        def set_property(self, prop: str, value: Any) -> Self:
            """Assign new value to user-defined property.

            Args:
                prop:
                    Name of property.
                value:
                    New value to be assigned for the property.
            """
            self.properties[prop] = value
            return self

        def build(self) -> MatchItem:
            """Obtain the data."""
            m = MatchItem(
                name=self.name,
                destinationItemId=self.destination_id,
                destinationItemName=self.destination_name,
                sourceItemId=self.source_id,
                sourceItemName=self.source_name,
            )
            for prop in self.properties:
                cast(dict[Any, Any], m)[prop] = self.properties[prop]
            if self.type is not None:
                m["type"] = self.type
            return m