"""Internal SaaS model: resources, operations, auth."""

from enum import Enum
from typing import Any, Optional

from pydantic import BaseModel, Field


class AuthType(str, Enum):
    api_key = "api_key"
    bearer = "bearer"
    oauth2 = "oauth2"


class AuthConfig(BaseModel):
    type: AuthType = AuthType.bearer
    env_var: str = Field(..., description="Env var name for token/key")


class Resource(BaseModel):
    """Logical resource (e.g. from OpenAPI tag or path prefix)."""
    name: str
    description: Optional[str] = None


class Operation(BaseModel):
    """One API operation (method + path)."""
    method: str = Field(..., description="HTTP method (get, post, etc.)")
    path: str = Field(..., description="Path (e.g. /pets)")
    operation_id: Optional[str] = None
    summary: Optional[str] = None
    description: Optional[str] = None
    tags: list[str] = Field(default_factory=list)
    parameters: list[dict[str, Any]] = Field(default_factory=list)
    request_body_schema: Optional[dict[str, Any]] = None
    response_info: Optional[str] = None


class SaaSModel(BaseModel):
    """Top-level model: everything we need to generate tools and prompt."""
    title: Optional[str] = None
    description: Optional[str] = None
    resources: list[Resource] = Field(default_factory=list)
    operations: list[Operation] = Field(default_factory=list)
    auth: Optional[AuthConfig] = None
