from datetime import datetime
from pydantic import BaseModel

from app.schemas.game import GameResponse
from app.schemas.challenge import ChallengeResponse


class AssignmentBase(BaseModel):
    pass


class CompleteAssignment(BaseModel):
    proof_url: str | None = None
    comment: str | None = None


class AssignmentResponse(BaseModel):
    id: int
    challenge: ChallengeResponse
    status: str
    proof_url: str | None = None
    proof_comment: str | None = None
    points_earned: int
    streak_at_completion: int | None = None
    started_at: datetime
    completed_at: datetime | None = None
    drop_penalty: int = 0  # Calculated penalty if dropped

    class Config:
        from_attributes = True


class SpinResult(BaseModel):
    assignment_id: int
    game: GameResponse
    challenge: ChallengeResponse
    can_drop: bool
    drop_penalty: int


class CompleteResult(BaseModel):
    points_earned: int
    streak_bonus: int
    total_points: int
    new_streak: int


class DropResult(BaseModel):
    penalty: int
    total_points: int
    new_drop_count: int


class EventAssignmentResponse(BaseModel):
    """Response for event-specific assignment (Common Enemy)"""
    assignment: AssignmentResponse | None
    event_id: int | None
    challenge_id: int | None
    is_completed: bool

    class Config:
        from_attributes = True
