# generated by datamodel-codegen:
#   filename:  webhook-payload.json
#   timestamp: 2025-11-15T22:03:55+00:00

from __future__ import annotations

from enum import Enum
from typing import Annotated, Any

from adcp.types.base import AdCPBaseModel
from pydantic import AwareDatetime, ConfigDict, Field

from . import task_status
from . import task_type as task_type_1


class Domain(Enum):
    media_buy = "media-buy"
    signals = "signals"


class Progress(AdCPBaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    current_step: Annotated[
        str | None, Field(description="Current step or phase of the operation")
    ] = None
    percentage: Annotated[
        float | None, Field(description="Completion percentage (0-100)", ge=0.0, le=100.0)
    ] = None
    step_number: Annotated[int | None, Field(description="Current step number", ge=1)] = None
    total_steps: Annotated[
        int | None, Field(description="Total number of steps in the operation", ge=1)
    ] = None


class WebhookPayload(AdCPBaseModel):
    model_config = ConfigDict(
        extra="allow",
    )
    context_id: Annotated[
        str | None,
        Field(
            description="Session/conversation identifier. Use this to continue the conversation if input-required status needs clarification or additional parameters."
        ),
    ] = None
    domain: Annotated[
        Domain | None,
        Field(
            description="AdCP domain this task belongs to. Helps classify the operation type at a high level."
        ),
    ] = None
    error: Annotated[
        str | None,
        Field(description="Error message for failed tasks. Only present when status is 'failed'."),
    ] = None
    message: Annotated[
        str | None,
        Field(
            description="Human-readable summary of the current task state. Provides context about what happened and what action may be needed."
        ),
    ] = None
    operation_id: Annotated[
        str | None,
        Field(
            description="Publisher-defined operation identifier correlating a sequence of task updates across webhooks."
        ),
    ] = None
    progress: Annotated[
        Progress | None,
        Field(
            description="Progress information for tasks still in 'working' state. Rarely seen in webhooks since 'working' tasks typically complete synchronously, but may appear if a task transitions from 'submitted' to 'working'."
        ),
    ] = None
    result: Annotated[
        dict[str, Any] | None,
        Field(
            description="Task-specific payload for this status update. Validated against the appropriate response schema based on task_type."
        ),
    ] = None
    status: Annotated[
        task_status.TaskStatus,
        Field(
            description="Current task status. Webhooks are only triggered for status changes after initial submission (e.g., submitted → input-required, submitted → completed, submitted → failed)."
        ),
    ]
    task_id: Annotated[
        str,
        Field(
            description="Unique identifier for this task. Use this to correlate webhook notifications with the original task submission."
        ),
    ]
    task_type: Annotated[
        task_type_1.TaskType,
        Field(
            description="Type of AdCP operation that triggered this webhook. Enables webhook handlers to route to appropriate processing logic."
        ),
    ]
    timestamp: Annotated[
        AwareDatetime, Field(description="ISO 8601 timestamp when this webhook was generated.")
    ]
