# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .feedback_priority import FeedbackPriority
from .feedback_status import FeedbackStatus
from .feedback_target_type import FeedbackTargetType
from .feedback_user_type import FeedbackUserType


class Feedback(UncheckedBaseModel):
    """
    Feedback entity stored in PostgreSQL.

    Represents human feedback on AI system outputs (workflow runs, copilot messages, etc.)
    """

    id: str = pydantic.Field()
    """
    Unique feedback ID (fb_*)
    """

    target_type: FeedbackTargetType = pydantic.Field()
    """
    Type of target being reviewed
    """

    target_id: str = pydantic.Field()
    """
    ID of the target entity
    """

    scorer_id: str = pydantic.Field()
    """
    ID of the HumanReviewScorer template used
    """

    user_type: typing.Optional[FeedbackUserType] = pydantic.Field(default=None)
    """
    Type of user providing feedback
    """

    created_by: typing.Optional[str] = pydantic.Field(default=None)
    """
    Internal Scout user ID (from JWT)
    """

    external_user_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    External customer user ID
    """

    external_user_metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(
        default=None
    )
    """
    Segment-style traits
    """

    score: typing.Optional[float] = pydantic.Field(default=None)
    """
    Numeric score (0-1) for continuous/categorical
    """

    selected_option: typing.Optional[str] = pydantic.Field(default=None)
    """
    Selected option label for categorical
    """

    comment: typing.Optional[str] = pydantic.Field(default=None)
    """
    Optional text comment/feedback
    """

    correction: typing.Optional[typing.Optional[typing.Any]] = pydantic.Field(default=None)
    """
    Correction data (for future use)
    """

    metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None)
    """
    Flexible metadata including user_id, session_id, etc.
    """

    status: typing.Optional[FeedbackStatus] = pydantic.Field(default=None)
    """
    Current status of the feedback
    """

    priority: typing.Optional[FeedbackPriority] = pydantic.Field(default=None)
    """
    Priority level for addressing this feedback
    """

    assigned_to: typing.Optional[str] = pydantic.Field(default=None)
    """
    User ID of team member assigned to this feedback
    """

    internal_notes: typing.Optional[str] = pydantic.Field(default=None)
    """
    Internal team notes (not visible to external users)
    """

    resolved_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Timestamp when feedback was marked as resolved
    """

    resolved_by: typing.Optional[str] = pydantic.Field(default=None)
    """
    User ID who resolved the feedback
    """

    organization_id: str = pydantic.Field()
    """
    Organization that owns this feedback
    """

    created_at: dt.datetime = pydantic.Field()
    """
    When feedback was created
    """

    updated_at: dt.datetime = pydantic.Field()
    """
    When feedback was last updated
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
