from datetime import datetime
from typing import Optional
from pydantic import Field
from src.apps.base.schemas.common import BaseSchema
from src.apps.payment_requests.enums import SplitPaymentTypes


class SplitPaymentRequestBase(BaseSchema):
    sequence: Optional[int] = Field(description="Quantity of line item")
    split_type: Optional[SplitPaymentTypes] = Field(
        description="A split could be done in two ways, percent or amount"
    )
    split_value: Optional[float] = Field(description="Value of the split being done")
    billing_date: Optional[datetime] = Field(
        description="Billing date and time of split as unix timestamp"
    )
    due_date: Optional[datetime] = Field(
        description="Due date and time of split as unix timestamp"
    )


class SplitPaymentRequestSchema(SplitPaymentRequestBase):
    id: int = Field(description="Id of Line Item resource")
    paid_date: Optional[datetime] = Field(
        description="Paid date and time of split as unix timestamp"
    )
    due_amount: Optional[float] = Field(
        description="Calculated final payable split amount"
    )


class SplitPaymentRequestCreate(SplitPaymentRequestBase):
    split_type: SplitPaymentTypes = Field(
        description="A split could be done in two ways, percent or amount"
    )
    split_value: float = Field(description="Value of the split being done")
    billing_date: datetime = Field(
        description="Billing date and time of split as unix timestamp"
    )
    due_date: datetime = Field(
        description="Due date and time of split as unix timestamp"
    )
    calculated_value: float = Field(
        description="Calculated amount of this split in cents"
    )


class SplitPaymentRequestUpdate(SplitPaymentRequestBase):
    object_id: Optional[int] = Field(description="ID of the split")
    calculated_value: float = Field(
        description="Calculated amount of this split in cents"
    )
