# app/modules/loyalty/schemas/points.py
"""
Pydantic schemas for points operations.
"""

from pydantic import BaseModel, Field


class PointsEarnRequest(BaseModel):
    """Schema for earning points from a purchase."""

    card_id: int | None = Field(
        None,
        description="Card ID (use this or qr_code)",
    )
    qr_code: str | None = Field(
        None,
        description="QR code data from card scan",
    )
    card_number: str | None = Field(
        None,
        description="Card number (manual entry)",
    )

    # Purchase info
    purchase_amount_cents: int = Field(
        ...,
        gt=0,
        description="Purchase amount in cents",
    )
    order_reference: str | None = Field(
        None,
        max_length=100,
        description="Order reference for tracking",
    )

    # Authentication
    staff_pin: str | None = Field(
        None,
        min_length=4,
        max_length=6,
        description="Staff PIN for verification",
    )

    # Optional metadata
    notes: str | None = Field(
        None,
        max_length=500,
        description="Optional note",
    )


class PointsEarnResponse(BaseModel):
    """Schema for points earning response."""

    success: bool = True
    message: str = "Points earned successfully"

    # Points info
    points_earned: int
    points_per_euro: int
    purchase_amount_cents: int

    # Card state after earning
    card_id: int
    card_number: str
    points_balance: int
    total_points_earned: int


class PointsRedeemRequest(BaseModel):
    """Schema for redeeming points for a reward."""

    card_id: int | None = Field(
        None,
        description="Card ID (use this or qr_code)",
    )
    qr_code: str | None = Field(
        None,
        description="QR code data from card scan",
    )
    card_number: str | None = Field(
        None,
        description="Card number (manual entry)",
    )

    # Reward selection
    reward_id: str = Field(
        ...,
        description="ID of the reward to redeem",
    )

    # Authentication
    staff_pin: str | None = Field(
        None,
        min_length=4,
        max_length=6,
        description="Staff PIN for verification",
    )

    # Optional metadata
    notes: str | None = Field(
        None,
        max_length=500,
        description="Optional note",
    )


class PointsRedeemResponse(BaseModel):
    """Schema for points redemption response."""

    success: bool = True
    message: str = "Reward redeemed successfully"

    # Reward info
    reward_id: str
    reward_name: str
    points_spent: int

    # Card state after redemption
    card_id: int
    card_number: str
    points_balance: int
    total_points_redeemed: int
