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

class UserCostShare(BaseModel):
    user_id: int
    user_identifier: str
    items_added_value: Decimal = Decimal("0.00")
    amount_due: Decimal
    balance: Decimal

    model_config = ConfigDict(from_attributes=True)

class ListCostSummary(BaseModel):
    list_id: int
    list_name: str
    total_list_cost: Decimal
    num_participating_users: int
    equal_share_per_user: Decimal
    user_balances: List[UserCostShare]

    model_config = ConfigDict(from_attributes=True)

class UserBalanceDetail(BaseModel):
    user_id: int
    user_identifier: str
    total_paid_for_expenses: Decimal = Decimal("0.00")
    total_share_of_expenses: Decimal = Decimal("0.00")
    total_settlements_paid: Decimal = Decimal("0.00")
    total_settlements_received: Decimal = Decimal("0.00")
    net_balance: Decimal = Decimal("0.00")
    model_config = ConfigDict(from_attributes=True)

class SuggestedSettlement(BaseModel):
    from_user_id: int
    from_user_identifier: str
    to_user_id: int
    to_user_identifier: str
    amount: Decimal
    model_config = ConfigDict(from_attributes=True)

class GroupBalanceSummary(BaseModel):
    group_id: int
    group_name: str
    overall_total_expenses: Decimal = Decimal("0.00")
    overall_total_settlements: Decimal = Decimal("0.00")
    user_balances: List[UserBalanceDetail]
    suggested_settlements: Optional[List[SuggestedSettlement]] = None 
    model_config = ConfigDict(from_attributes=True)