# generated by datamodel-codegen:
#   filename:  openapi.json
#   timestamp: 2026-02-22T16:52:47+00:00

from __future__ import annotations
from pydantic import BaseModel, Field
from datetime import datetime
from typing import Any


class AdminNotificationOutSchema(BaseModel):
    """
    Admin view – same fields, explicit class for OpenAPI separation.
    """
    body: str = Field(..., title='Body')
    created_at: datetime = Field(..., title='Created At')
    deleted_at: datetime | None = Field(None, title='Deleted At')
    family: str = Field(..., title='Family')
    id: str = Field(..., title='Id')
    nudge_log_id: str | None = Field(None, title='Nudge Log Id')
    read_at: datetime | None = Field(None, title='Read At')
    rule_id: str = Field(..., title='Rule Id')
    severity: str = Field(..., title='Severity')
    status: str = Field(..., title='Status')
    title: str = Field(..., title='Title')
    type: str = Field(..., title='Type')
    user_id: str = Field(..., title='User Id')


class DeliveryJobOutSchema(BaseModel):
    body: str = Field(..., title='Body')
    channel: str = Field(..., title='Channel')
    created_at: datetime = Field(..., title='Created At')
    dedup_key: str = Field(..., title='Dedup Key')
    destination: str = Field(..., title='Destination')
    job_id: str = Field(..., title='Job Id')
    nudge_id: str = Field(..., title='Nudge Id')
    rule_id: str = Field(..., title='Rule Id')
    title: str = Field(..., title='Title')
    user_id: str = Field(..., title='User Id')


class DigitalTwinEventSchema(BaseModel):
    event_type: str = Field(..., title='Event Type')
    facts: dict[str, Any] | None = Field(None, description='Enriched facts computed by Digital Twin', title='Facts')
    payload: dict[str, Any] | None = Field(None, title='Payload')
    timestamp: datetime | None = Field(None, title='Timestamp')
    user_id: str = Field(..., title='User Id')


class EngineResultOutSchema(BaseModel):
    details: dict[str, Any] | None = Field(None, title='Details')
    reason: str | None = Field(None, title='Reason')
    status: str = Field(..., title='Status')


class IngestErrorDetailSchema(BaseModel):
    error: str = Field(..., title='Error')
    errors: list[str] | None = Field(None, title='Errors')
    reason: str | None = Field(None, title='Reason')
    results: list[EngineResultOutSchema] | None = Field(None, title='Results')


class NotificationOutSchema(BaseModel):
    """
    User-facing notification. Fields are proper columns, not buried JSON.
    """
    body: str = Field(..., title='Body')
    created_at: datetime = Field(..., title='Created At')
    deleted_at: datetime | None = Field(None, description='Null if not soft-deleted', title='Deleted At')
    family: str = Field(..., description='energy | onboarding | seasonal | …', title='Family')
    id: str = Field(..., title='Id')
    nudge_log_id: str | None = Field(None, description='Originating engine audit row', title='Nudge Log Id')
    read_at: datetime | None = Field(None, description='Null if unread', title='Read At')
    rule_id: str = Field(..., title='Rule Id')
    severity: str = Field(..., description='info | warning | critical', title='Severity')
    status: str = Field(..., description='pending | sent | suppressed | failed', title='Status')
    title: str = Field(..., title='Title')
    type: str = Field(..., description='informative | opportunity | alert', title='Type')
    user_id: str = Field(..., title='User Id')


class NudgeCreatedItemSchema(BaseModel):
    deliveries: list[DeliveryJobOutSchema] = Field(..., title='Deliveries')
    nudge_id: str = Field(..., title='Nudge Id')
    rule_id: str = Field(..., title='Rule Id')


class SendTestRequestSchema(BaseModel):
    """
    Admin-only: user_id is explicit because an admin targets any user.
    """
    body: str | None = Field('Hello!', examples=['Hello!'], title='Body')
    title: str | None = Field('Test', examples=['Test'], title='Title')
    url: str | None = Field('/', examples=['/'], title='Url')
    user_id: str = Field(..., description='Target user ID', title='User Id')


class SendTestResponseSchema(BaseModel):
    failed: int | None = Field(None, title='Failed')
    sent: int | None = Field(None, title='Sent')
    status: str = Field(..., title='Status')


class StatusResponseSchema(BaseModel):
    status: str = Field(..., examples=['ok'], title='Status')


class UnsubscribeRequestSchema(BaseModel):
    """
    user_id is derived from the JWT – not accepted from the caller.
    """
    endpoint: str = Field(..., title='Endpoint')


class ValidationErrorSchema(BaseModel):
    ctx: dict[str, Any] | None = Field(None, title='Context')
    input: Any | None = Field(None, title='Input')
    loc: list[str | int] = Field(..., title='Location')
    msg: str = Field(..., title='Message')
    type: str = Field(..., title='Error Type')


class VapidPublicKeyResponseSchema(BaseModel):
    public_key: str = Field(..., title='Public Key')


class WebPushKeysInSchema(BaseModel):
    auth: str = Field(..., title='Auth')
    p256dh: str = Field(..., title='P256Dh')


class WebPushSubscriptionInSchema(BaseModel):
    endpoint: str = Field(..., title='Endpoint')
    keys: WebPushKeysInSchema


class HTTPValidationErrorSchema(BaseModel):
    detail: list[ValidationErrorSchema] | None = Field(None, title='Detail')


class IngestAcceptedResponseSchema(BaseModel):
    created: list[NudgeCreatedItemSchema] = Field(..., title='Created')
    delivery: str | None = Field('suppressed', examples=['suppressed'], title='Delivery')
    status: str | None = Field('accepted', examples=['accepted'], title='Status')
    suppressed: list[EngineResultOutSchema] = Field(..., title='Suppressed')


class IngestOkResponseSchema(BaseModel):
    created: list[NudgeCreatedItemSchema] = Field(..., title='Created')
    status: str | None = Field('ok', examples=['ok'], title='Status')
    suppressed: list[EngineResultOutSchema] = Field(..., title='Suppressed')


class SubscribeRequestSchema(BaseModel):
    """
    user_id is derived from the JWT – not accepted from the caller.
    """
    subscription: WebPushSubscriptionInSchema
