55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
from pydantic import BaseModel, ConfigDict
|
|
from typing import List, Optional
|
|
from decimal import Decimal
|
|
|
|
class UserCostShare(BaseModel):
|
|
user_id: int
|
|
user_identifier: str # Name or email
|
|
items_added_value: Decimal = Decimal("0.00") # Total value of items this user added
|
|
amount_due: Decimal # The user's share of the total cost (for equal split, this is total_cost / num_users)
|
|
balance: Decimal # items_added_value - amount_due
|
|
|
|
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 # Name or email
|
|
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") # (paid_for_expenses + settlements_received) - (share_of_expenses + settlements_paid)
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
class SuggestedSettlement(BaseModel):
|
|
from_user_id: int
|
|
from_user_identifier: str # Name or email of payer
|
|
to_user_id: int
|
|
to_user_identifier: str # Name or email of payee
|
|
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]
|
|
# Optional: Could add a list of suggested settlements to zero out balances
|
|
suggested_settlements: Optional[List[SuggestedSettlement]] = None
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
# class SuggestedSettlement(BaseModel):
|
|
# from_user_id: int
|
|
# to_user_id: int
|
|
# amount: Decimal |