from pydantic import BaseModel, ConfigDict, field_validator
from typing import Optional, List
from decimal import Decimal
from datetime import datetime

from app.schemas.user import UserPublic # Assuming UserPublic is defined here

class SettlementActivityBase(BaseModel):
    expense_split_id: int
    paid_by_user_id: int
    amount_paid: Decimal
    paid_at: Optional[datetime] = None

class SettlementActivityCreate(SettlementActivityBase):
    @field_validator('amount_paid')
    @classmethod
    def amount_must_be_positive(cls, v: Decimal) -> Decimal:
        if v <= Decimal("0"):
            raise ValueError("Amount paid must be a positive value.")
        return v

class SettlementActivityPublic(SettlementActivityBase):
    id: int
    created_by_user_id: int # User who recorded this activity
    created_at: datetime
    updated_at: datetime
    
    payer: Optional[UserPublic] = None # User who made this part of the payment
    creator: Optional[UserPublic] = None # User who recorded this activity

    model_config = ConfigDict(from_attributes=True)

# Schema for updating a settlement activity (if needed in the future)
# class SettlementActivityUpdate(BaseModel):
#     amount_paid: Optional[Decimal] = None
#     paid_at: Optional[datetime] = None

#     @field_validator('amount_paid')
#     @classmethod
#     def amount_must_be_positive_if_provided(cls, v: Optional[Decimal]) -> Optional[Decimal]:
#         if v is not None and v <= Decimal("0"):
#             raise ValueError("Amount paid must be a positive value.")
#         return v
