from datetime import datetime
from typing import Literal

from pydantic import BaseModel, ConfigDict, Field, field_validator

CardKeyType = Literal["时长", "点数"]


class CardKeyActivateRequest(BaseModel):
    username: str = Field(min_length=1, max_length=64)
    serial_number: str = Field(min_length=1, max_length=64)

    @field_validator("username")
    @classmethod
    def normalize_username(cls, value: str) -> str:
        stripped = value.strip()
        if not stripped:
            raise ValueError("请输入用户名")
        return stripped

    @field_validator("serial_number")
    @classmethod
    def normalize_serial(cls, value: str) -> str:
        stripped = value.strip().upper()
        if not stripped:
            raise ValueError("请输入卡密")
        return stripped


class CardKeyActivateResponse(BaseModel):
    card_type: CardKeyType
    vip_end_time: datetime | None = None
    points: float | None = None
    added_days: int | None = None
    added_points: float | None = None
