# app/modules/journals/schemas.py
from pydantic import BaseModel, field_validator
from typing import List
from decimal import Decimal
from datetime import date

class JournalLineCreate(BaseModel):
    account_id: int
    debit: Decimal = 0
    credit: Decimal = 0

    @field_validator("debit", "credit")
    @classmethod
    def non_negative(cls, v):
        if v < 0:
            raise ValueError("金額は0以上で入力してください")
        return v

class JournalCreate(BaseModel):
    journal_date: date
    description: str
    lines: List[JournalLineCreate]

    @field_validator("lines")
    @classmethod
    def validate_lines(cls, v):
        if len(v) < 2:
            raise ValueError("仕訳明細は2行以上必要です")
        return v
