"""Campaign Engine DTOs — Phase 7.4."""
from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field

from app.models.types import CampaignApplicationStatus
from app.schemas.common import ORMBase

_FORBID = ConfigDict(extra="forbid")


class CampaignRulesUpdateRequest(BaseModel):
    model_config = _FORBID

    rules: dict = Field(default_factory=dict)


class ApplyCampaignRequest(BaseModel):
    model_config = _FORBID

    member_id: UUID
    point_account_id: UUID | None = None
    base_amount: int | None = Field(default=None, ge=0)
    idempotency_key: str | None = Field(default=None, max_length=100)
    metadata_json: dict | None = None


class CampaignApplicationRead(ORMBase):
    id: UUID
    tenant_id: UUID
    campaign_id: UUID
    program_id: UUID
    member_id: UUID
    point_account_id: UUID
    rule_version: int
    points_granted: int
    ledger_entry_id: UUID | None
    status: CampaignApplicationStatus
    idempotency_key: str | None
    actor_user_id: str | None
    metadata_json: dict | None
    created_at: datetime


class CampaignApplicationPage(BaseModel):
    items: list[CampaignApplicationRead]
    total: int
    offset: int
    limit: int
