"""Reward redemption DTOs — Phase 7.3."""
from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field

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

_FORBID = ConfigDict(extra="forbid")


class RedeemRequest(BaseModel):
    model_config = _FORBID

    member_id: UUID
    idempotency_key: str | None = Field(default=None, max_length=100)
    reason: str | None = Field(default=None, max_length=500)
    metadata_json: dict | None = None


class CancelRequest(BaseModel):
    model_config = _FORBID

    reason: str = Field(max_length=500)


class RewardRedemptionRead(ORMBase):
    id: UUID
    tenant_id: UUID
    program_id: UUID
    reward_id: UUID
    member_id: UUID
    point_account_id: UUID
    status: RedemptionStatus
    points_spent: int
    ledger_entry_id: UUID | None
    voucher_code: str
    idempotency_key: str | None
    reason: str | None
    cancel_reason: str | None
    fulfilled_at: datetime | None
    cancelled_at: datetime | None
    metadata_json: dict | None
    actor_user_id: str | None
    created_at: datetime
    updated_at: datetime


class RewardRedemptionPage(BaseModel):
    items: list[RewardRedemptionRead]
    total: int
    offset: int
    limit: int
