"""
User-friendly wrapper around auto-generated client.

This provides a clean, discoverable API with full autocomplete support.

⚠️ AUTO-GENERATED - DO NOT EDIT MANUALLY
   Regenerated by: tools/ci/generate-easy-wrapper.py
"""

from typing import Optional
from uuid import UUID

from constec.erp.client import Client as _GeneratedClient
from constec.erp.models import SupplierSchema, CustomerSchema, SellerSchema
from constec.erp.api.customers import list_customers_erp_v1_customers_get
from constec.erp.api.suppliers import list_suppliers_erp_v1_suppliers_get
from constec.erp.api.sellers import list_sellers_erp_v1_sellers_get


class ErpClient:
    """
    Easy-to-use client for the Constec ERP API.
    
    Example:
        >>> async with ErpClient("http://localhost:8001") as client:
        ...     suppliers = await client.get_suppliers(company_id=uuid)
        ...     print(f"Found {len(suppliers)} suppliers")
    """
    
    def __init__(self, base_url: str):
        """
        Initialize the ERP client.
        
        Args:
            base_url: Base URL of the ERP API (e.g., "http://localhost:8001")
        """
        self._client = _GeneratedClient(base_url=base_url)  # type: ignore[call-arg]
    
    async def __aenter__(self) -> "ErpClient":
        await self._client.__aenter__()
        return self
    
    async def __aexit__(self, *args, **kwargs):
        await self._client.__aexit__(*args, **kwargs)

    async def get_customers(
        self,
        company_id: UUID,
        *,
        limit: int = 100,
        offset: int = 0,
        name: Optional[str] = None,
        cuit: Optional[str] = None,
    ) -> list[CustomerSchema]:
        """
        List Customers
        
        Args:
            company_id: UUID of the company
            limit: Maximum number of results (default: 100)
            offset: Offset for pagination (default: 0)
            name: Filter by name (optional)
            cuit: Filter by CUIT number (optional)
        
        Returns:
            List of customers
        """
        response = await list_customers_erp_v1_customers_get.asyncio_detailed(
            client=self._client,
            company_id=company_id,  # type: ignore[arg-type]
            limit=limit,
            offset=offset,
            name=name,
            cuit=cuit,
        )
        
        if response.status_code == 200 and response.parsed:
            return response.parsed.items or []  # type: ignore[union-attr]
        
        return []

    async def get_suppliers(
        self,
        company_id: UUID,
        *,
        limit: int = 100,
        offset: int = 0,
        name: Optional[str] = None,
        cuit: Optional[str] = None,
    ) -> list[SupplierSchema]:
        """
        List Suppliers
        
        Args:
            company_id: UUID of the company
            limit: Maximum number of results (default: 100)
            offset: Offset for pagination (default: 0)
            name: Filter by name (optional)
            cuit: Filter by CUIT number (optional)
        
        Returns:
            List of suppliers
        """
        response = await list_suppliers_erp_v1_suppliers_get.asyncio_detailed(
            client=self._client,
            company_id=company_id,  # type: ignore[arg-type]
            limit=limit,
            offset=offset,
            name=name,
            cuit=cuit,
        )
        
        if response.status_code == 200 and response.parsed:
            return response.parsed.items or []  # type: ignore[union-attr]
        
        return []

    async def get_sellers(
        self,
        company_id: UUID,
        *,
        limit: int = 100,
        offset: int = 0,
        name: Optional[str] = None,
    ) -> list[SellerSchema]:
        """
        List Sellers
        
        Args:
            company_id: UUID of the company
            limit: Maximum number of results (default: 100)
            offset: Offset for pagination (default: 0)
            name: Filter by name (optional)
        
        Returns:
            List of sellers
        """
        response = await list_sellers_erp_v1_sellers_get.asyncio_detailed(
            client=self._client,
            company_id=company_id,  # type: ignore[arg-type]
            limit=limit,
            offset=offset,
            name=name,
        )
        
        if response.status_code == 200 and response.parsed:
            return response.parsed.items or []  # type: ignore[union-attr]
        
        return []


__all__ = ["ErpClient", "SupplierSchema", "CustomerSchema", "SellerSchema"]
