49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
# app/schemas/expense.py
|
|
from pydantic import BaseModel, ConfigDict
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
from decimal import Decimal
|
|
|
|
from .user import UserPublic # Assuming UserPublic schema exists
|
|
from app.models import SplitTypeEnum, SettlementActivityTypeEnum # Import Enums from models
|
|
|
|
# Represents a single user's share of an expense
|
|
class ExpenseSharePublic(BaseModel):
|
|
id: int
|
|
expense_record_id: int
|
|
user_id: int
|
|
amount_owed: Decimal
|
|
is_paid: bool
|
|
user: Optional[UserPublic] = None # Include user details for context
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
# Represents a log of settlement actions
|
|
class SettlementActivityPublic(BaseModel):
|
|
id: int
|
|
expense_record_id: int
|
|
payer_user_id: int # Who marked it paid/unpaid
|
|
affected_user_id: int # Whose share status changed
|
|
activity_type: SettlementActivityTypeEnum # Use the Enum
|
|
timestamp: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
# Represents a finalized expense split record for a list
|
|
class ExpenseRecordPublic(BaseModel):
|
|
id: int
|
|
list_id: int
|
|
calculated_at: datetime
|
|
calculated_by_id: int
|
|
total_amount: Decimal
|
|
split_type: SplitTypeEnum # Use the Enum
|
|
is_settled: bool
|
|
participants: List[int] # List of user IDs who participated
|
|
shares: List[ExpenseSharePublic] = [] # Include the individual shares
|
|
settlement_activities: List[SettlementActivityPublic] = [] # Include settlement history
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
# Schema for the request body of the settle endpoint
|
|
class SettleShareRequest(BaseModel):
|
|
affected_user_id: int # The ID of the user whose share is being settled |