"""
Payment schemas for financial transactions.
"""
from typing import Optional, List
from datetime import datetime
from pydantic import BaseModel, Field

from app.models.payment import PaymentMethod, PaymentStatus


class PaymentBase(BaseModel):
    """Base payment schema."""
    payment_method: PaymentMethod
    amount: float = Field(..., gt=0)
    currency: str = Field("EUR", max_length=3)
    reference: Optional[str] = Field(None, max_length=200)
    notes: Optional[str] = None


class PaymentCreate(PaymentBase):
    """Schema for creating a payment."""
    folio_id: int


class PaymentResponse(PaymentBase):
    """Schema for payment response."""
    id: int
    folio_id: int
    status: PaymentStatus
    payment_date: datetime
    received_by_id: Optional[int] = None
    original_payment_id: Optional[int] = None
    created_at: datetime

    class Config:
        from_attributes = True


class PaymentRefundRequest(BaseModel):
    """Schema for refunding a payment."""
    payment_id: int
    amount: Optional[float] = Field(None, gt=0)
    reason: str = Field(..., min_length=1, max_length=500)


class PaymentSummary(BaseModel):
    """Schema for payment summary."""
    total_payments: float
    by_method: dict
    currency: str


class DailyPaymentReport(BaseModel):
    """Schema for daily payment report."""
    date: datetime
    payments: List[PaymentResponse]
    total_by_method: dict
    grand_total: float
    currency: str
