from __future__ import annotations
from typing import Any, Optional, List
from pydantic import BaseModel
try:
    from .models import Address as AddressModel, ProviderAccount as ProviderAccountModel, ParcelTemplate as ParcelTemplateModel, Webhook as WebhookModel, City as CityModel, District as DistrictModel
except Exception:
    # Fallback minimal models if not generated by OpenAPI
    class AddressModel(BaseModel):
        id: Optional[str] = None
        cityCode: Optional[str] = None
        cityName: Optional[str] = None
        districtID: Optional[int] = None
        districtName: Optional[str] = None
        address1: Optional[str] = None

    class ProviderAccountModel(BaseModel):
        id: Optional[str] = None
        providerCode: Optional[str] = None
        username: Optional[str] = None
        name: Optional[str] = None
        isActive: Optional[bool] = None

    class ParcelTemplateModel(BaseModel):
        id: Optional[str] = None
        length: Optional[str] = None
        width: Optional[str] = None
        height: Optional[str] = None
        distanceUnit: Optional[str] = None
        weight: Optional[str] = None
        massUnit: Optional[str] = None

    class WebhookModel(BaseModel):
        id: Optional[str] = None
        url: Optional[str] = None

    class CityModel(BaseModel):
        cityCode: Optional[str] = None
        countryCode: Optional[str] = None
        name: Optional[str] = None

    class DistrictModel(BaseModel):
        districtID: Optional[int] = None
        name: Optional[str] = None


class Envelope(BaseModel):
    result: Optional[bool] = None
    code: Optional[str] = None
    message: Optional[str] = None
    additionalMessage: Optional[str] = None
    limit: Optional[int] = None
    page: Optional[int] = None
    totalRows: Optional[int] = None
    totalPages: Optional[int] = None
    data: Any = None


class Shipment(BaseModel):
    id: str
    statusCode: Optional[str] = None
    trackingNumber: Optional[str] = None
    trackingUrl: Optional[str] = None
    labelURL: Optional[str] = None
    acceptedOfferID: Optional[str] = None
    createdAt: Optional[str] = None
    updatedAt: Optional[str] = None
    # allow extra
    class Config:
        extra = "allow"


class Transaction(BaseModel):
    id: str
    offerID: str
    isPayed: Optional[bool] = None
    transactionType: Optional[str] = None
    shipment: Optional[Shipment] = None
    createdAt: Optional[str] = None
    class Config:
        extra = "allow"


class ListParams(BaseModel):
    limit: Optional[int] = None
    page: Optional[int] = None
    sortBy: Optional[str] = None
    filter: Optional[str] = None
    startDate: Optional[str] = None
    endDate: Optional[str] = None
    statusFilter: Optional[str] = None
    invoiceID: Optional[str] = None
    merchantCode: Optional[str] = None
    orderNumber: Optional[str] = None
    providerServiceCode: Optional[str] = None
    storeIdentifier: Optional[str] = None
    isReturned: Optional[bool] = None


class ShipmentsListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    limit: Optional[int] = None
    page: Optional[int] = None
    totalRows: Optional[int] = None
    totalPages: Optional[int] = None
    data: list[Shipment]


class AddressesListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    limit: Optional[int] = None
    page: Optional[int] = None
    totalRows: Optional[int] = None
    totalPages: Optional[int] = None
    data: list[AddressModel]


class ProviderAccountsListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    data: list[ProviderAccountModel]


class ParcelTemplatesListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    data: list[ParcelTemplateModel]


class WebhooksListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    data: list[WebhookModel]


class CitiesListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    data: list[CityModel]


class DistrictsListResponse(BaseModel):
    result: Optional[bool] = None
    additionalMessage: Optional[str] = None
    data: list[DistrictModel]
