from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict, Field


class EasybillBaseModel(BaseModel):
    model_config = ConfigDict(extra="allow", populate_by_name=True)


class Pagination(EasybillBaseModel):
    page: int = 1
    pages: int = 1
    limit: int = 100
    total: int = 0


class PagedResult(Pagination):
    items: list[Any] = Field(default_factory=list)


class Customer(EasybillBaseModel):
    id: int | None = None
    number: str | None = None
    company_name: str | None = None
    first_name: str | None = None
    last_name: str | None = None
    email: str | None = None
    emails: list[str] = Field(default_factory=list)


class Document(EasybillBaseModel):
    id: int | None = None
    number: str | None = None
    customer_id: int | None = None
    type: str | None = None
    status: str | None = None
    amount: int | None = None
    amount_net: int | None = None
    title: str | None = None
    is_draft: bool | None = None


class WebhookSubscription(EasybillBaseModel):
    id: int | None = None
    url: str
    description: str
    secret: str
    content_type: str = "json"
    events: list[str] = Field(default_factory=list)
    is_active: bool = False


class WebhookEnvelope(EasybillBaseModel):
    event: str
    delivery_id: str
    payload: dict[str, Any] = Field(default_factory=dict)
    resource_id: int | None = None
    headers: dict[str, str] = Field(default_factory=dict)
