# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.credentials2 import Credentials2
from typing import Optional, Set
from typing_extensions import Self

class SharePointConfig(BaseModel):
    """
    Microsoft SharePoint and OneDrive for Business configuration.  Enables Mixpeek to connect to SharePoint sites, document libraries, and OneDrive for Business for automated file ingestion and synchronization.  Architecture:     SharePoint hierarchy: Tenant → Sites → Drives (Document Libraries) → Items     - site_id: Identifies the SharePoint site     - drive_id: Identifies a specific document library within the site     - folder_path: Path within the document library  Authentication Methods:     1. Client Credentials (RECOMMENDED for production):         - App-only access without user interaction         - Requires admin consent for Graph API permissions         - Access level determined by app permissions      2. Delegated:         - User-level access via OAuth consent         - Access limited to user's permissions         - Requires refresh token management  Requirements:     - Azure AD application registration     - Microsoft Graph API permissions (Sites.Read.All, Files.Read.All)     - Network connectivity to graph.microsoft.com  Use Cases:     - Sync SharePoint document libraries     - Ingest enterprise collaboration files     - Monitor and process uploaded documents     - Archive compliance-sensitive materials  Example:     ```python     config = {         \"provider_type\": \"sharepoint\",         \"credentials\": {             \"type\": \"client_credentials\",             \"tenant_id\": \"12345678-...\",             \"client_id\": \"87654321-...\",             \"client_secret\": \"your-secret\",         },         \"site_id\": \"contoso.sharepoint.com,guid1,guid2\",         \"drive_id\": \"b!abc123...\",         \"folder_path\": \"/Shared Documents/Marketing\",     }     ```
    """ # noqa: E501
    provider_type: Optional[StrictStr] = 'sharepoint'
    credentials: Credentials2
    site_id: Optional[StrictStr] = Field(default=None, description="NOT REQUIRED if using personal OneDrive. SharePoint site identifier for targeting a specific site. Format: '{hostname},{site-collection-id},{web-id}' or site URL. Find via: Microsoft Graph API GET /sites?search={keyword} Example: 'contoso.sharepoint.com,12345678-...,87654321-...'")
    drive_id: Optional[StrictStr] = Field(default=None, description="NOT REQUIRED if you want to use the default document library. Specific drive (document library) ID within the site. Find via: GET /sites/{site-id}/drives Format: Base64-encoded ID starting with 'b!'")
    folder_path: Optional[StrictStr] = Field(default=None, description="NOT REQUIRED. Path within the drive to sync from. If omitted, syncs from the root of the drive. Format: Forward-slash separated path (e.g., '/Documents/Marketing'). Note: Leading slash is optional.")
    __properties: ClassVar[List[str]] = ["provider_type", "credentials", "site_id", "drive_id", "folder_path"]

    @field_validator('provider_type')
    def provider_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['sharepoint']):
            raise ValueError("must be one of enum values ('sharepoint')")
        return value

    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 SharePointConfig 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,
        )
        # override the default output from pydantic by calling `to_dict()` of credentials
        if self.credentials:
            _dict['credentials'] = self.credentials.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "provider_type": obj.get("provider_type") if obj.get("provider_type") is not None else 'sharepoint',
            "credentials": Credentials2.from_dict(obj["credentials"]) if obj.get("credentials") is not None else None,
            "site_id": obj.get("site_id"),
            "drive_id": obj.get("drive_id"),
            "folder_path": obj.get("folder_path")
        })
        return _obj


