"""
Pydantic schemas for service booking-related requests and responses.
"""
from pydantic import BaseModel, Field, model_validator
from typing import Optional, List
from ...bookings.schemas.booking import ServiceItemSchema


class CreateServiceBookingRequest(BaseModel):
    """Schema for creating a service booking."""
    services: List[ServiceItemSchema] = Field(..., min_length=1, description="List of services to book")
    total_amount: float = Field(..., gt=0, description="Total amount for the booking")
    notes: Optional[str] = Field(None, max_length=1000, description="Additional notes")
    
    @model_validator(mode='after')
    def validate_total_amount(self):
        """Validate that total amount matches calculated total."""
        calculated = sum(item.quantity * 1.0 for item in self.services)  # Will be validated against service prices in route
        # Note: We can't validate exact amount here without service prices, but we validate structure
        if self.total_amount <= 0:
            raise ValueError("Total amount must be greater than 0")
        return self
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "services": [
                    {"service_id": 1, "quantity": 2}
                ],
                "total_amount": 100.00,
                "notes": "Special request"
            }
        }
    }


class CreateServicePaymentIntentRequest(BaseModel):
    """Schema for creating a Stripe payment intent for service booking."""
    amount: float = Field(..., gt=0, description="Payment amount")
    currency: str = Field("usd", max_length=3, description="Currency code")
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "amount": 100.00,
                "currency": "usd"
            }
        }
    }


class ConfirmServicePaymentRequest(BaseModel):
    """Schema for confirming a service payment."""
    payment_intent_id: str = Field(..., min_length=1, description="Stripe payment intent ID")
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "payment_intent_id": "pi_1234567890"
            }
        }
    }

