from pydantic import Field
from typing import List

from .models import ContractTemplate, ProvisionTemplate, PartyTemplate, ProvisionTemplateReference, DictionaryEntry
from ..core.schemas import Writer
from ..core.models import RichtextMultiline, RichtextSingleline


class ContractTemplateRead(ContractTemplate):
    pass


class ContractTemplateCreate(Writer):
    name: str = Field(title="Nom")
    title: str = Field(title="Titre")
    parties: List[PartyTemplate] = Field(default=[], title="Parties")
    provisions: List[ProvisionTemplateReference] = Field(
        default=[],
        props={"items-per-row": "1", "numbered": True},
        title="Clauses"
    )
    variables: List[DictionaryEntry] = Field(
        default=[],
        format="dictionary",
        props={"required": False},
        title="Variables"
    )

    class Config:
        title = 'Template de Contrat'


class ContractTemplateUpdate(ContractTemplateCreate):
    pass


class ProvisionTemplateRead(ProvisionTemplate):
    pass


class ProvisionTemplateCreate(Writer):
    name: str = Field(title="Nom")
    title: str = RichtextSingleline(title="Titre")
    body: str = RichtextMultiline(title="Corps")

    class Config:
        title = 'Template de Clause'


class ProvisionTemplateUpdate(ProvisionTemplateCreate):
    pass
