# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.auth_type import AuthType
from typing import Optional, Set
from typing_extensions import Self

class AuthConfig(BaseModel):
    """
    Authentication configuration for API calls.  Defines how to authenticate with external APIs using credentials stored in the organization secrets vault. Credentials are NEVER stored in the stage configuration - only references to vault secrets.  **⚠️ CRITICAL SECURITY WARNINGS**: - NEVER store actual credentials in configuration - ALWAYS use secret_ref to reference vault secrets - Credentials are encrypted at rest in vault - Decrypted values never appear in logs or API responses  **How It Works**: 1. Store secret via: POST /v1/organizations/secrets 2. Reference secret via: auth.secret_ref in stage config 3. At runtime: Secret is retrieved, decrypted, and injected into request 4. Security: Original secret value never exposed or logged  **Requirements**: - type: REQUIRED, authentication method (none, api_key, bearer, basic, custom_header) - secret_ref: REQUIRED (except for type=none), name of secret in vault - key: REQUIRED (for api_key and custom_header types), header/query param name - location: OPTIONAL (for api_key type), 'header' or 'query' (default: header)  **Supported Authentication Types**: - Bearer tokens (OAuth 2.0, JWT): Most modern APIs - API keys: Weather APIs, Maps, etc. - Basic auth: Legacy systems - Custom headers: Non-standard auth schemes
    """ # noqa: E501
    type: Optional[AuthType] = Field(default=None, description="REQUIRED. Authentication method to use. Options: none (public API), api_key (API keys), bearer (OAuth/JWT), basic (HTTP Basic Auth), custom_header (non-standard headers). See AuthType enum for detailed description of each type.")
    secret_ref: Optional[StrictStr] = Field(default=None, description="REQUIRED (except for type=none). Name of secret in organization vault. The secret must be created first via POST /v1/organizations/secrets. Format: Use the exact secret_name from vault (e.g., 'stripe_api_key'). At runtime, the secret value is securely retrieved and decrypted. The decrypted value is then injected into the request per auth type. SECURITY: NEVER store actual credentials here - only the reference name. Examples: 'stripe_api_key', 'github_pat', 'weather_api_key'")
    location: Optional[StrictStr] = Field(default=None, description="OPTIONAL (for api_key type only). Where to inject the API key. Options: 'header' (recommended, more secure) or 'query' (less secure). Default: 'header' if not specified. Query parameters appear in URLs and logs - use headers when possible. Ignored for other auth types (bearer, basic, custom_header).")
    key: Optional[StrictStr] = Field(default=None, description="REQUIRED (for api_key and custom_header types). Header name or query parameter name for authentication. For api_key with location=header: Header name like 'X-API-Key', 'Authorization'. For api_key with location=query: Query param like 'apikey', 'api_key', 'key'. For custom_header: Any custom header name like 'X-Custom-Auth', 'X-Token'. Ignored for bearer and basic types (use standard headers). Common patterns: 'X-API-Key', 'Authorization', 'X-Auth-Token'")
    __properties: ClassVar[List[str]] = ["type", "secret_ref", "location", "key"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of AuthConfig from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AuthConfig from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "secret_ref": obj.get("secret_ref"),
            "location": obj.get("location"),
            "key": obj.get("key")
        })
        return _obj


