
    inC                         d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZ d dlZd dlZ ej"                  e      Z G d d	      Zy)
    )Optional)NotFoundExceptionPineconeException)	ApiClient)ProjectsApi)parse_non_empty_argsrequire_kwargs)CreateProjectRequestUpdateProjectRequestNc                   b   e Zd ZdZdefdZed        Zeddee	   dee	   fd       Z
eddee	   dee	   fd	       Zeddee	   dee	   fd
       Zeddee	   dee	   fd       Ze	 	 dde	dee   dee   fd       Ze	 	 	 dde	dee	   dee   dee   fd       Ze	 	 	 dde	dededefd       Zy)ProjectResourcea  
    This class is used to create, delete, list, fetch, and update projects.

    .. note::
        The class should not be instantiated directly. Instead, access this classes
        methods through the :class:`pinecone.Admin` class's
        :attr:`project` or :attr:`projects` attributes.

        .. code-block:: python

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            # Now call project methods on the projects namespace
            project = admin.projects.create(
                name="my-project",
                max_pods=10,
                force_encryption_with_cmek=False
            )
    
api_clientc                 4    t        |      | _        || _        y)as  
        Initialize the ProjectResource.

        .. warning::
            This class should not be instantiated directly. Instead, access this classes
            methods through the :class:`pinecone.Admin` class's
            :attr:`project` or :attr:`projects` attributes.

        :param api_client: The API client to use.
        :type api_client: ApiClient
        )r   N)r   _projects_api_api_client)selfr   s     r/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/admin/resources/project.py__init__zProjectResource.__init__&   s     )J?%    c                 6    | j                   j                         S )a  
        List all projects in the organization.

        :return: An object with a list of projects.
        :rtype: {"data": [Project]}

        .. code-block:: python
            :caption: List all projects in the organization
            :emphasize-lines: 8

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            # List all projects in the organization
            projects_response = admin.projects.list()
            for project in projects_response.data:
                print(project.id)
                print(project.name)
                print(project.max_pods)
                print(project.force_encryption_with_cmek)
        )r   list_projects)r   s    r   listzProjectResource.list5   s    4 !!//11r   N
project_idnamec                    ||t        d      ||t        d      || j                  j                  |      S | j                         j                  }|D cg c]  }|j
                  |k(  s| }}t        |      dk(  rt        d| d      t        |      dkD  r*|D cg c]  }|j                   }}t        d| d	|       |d   S c c}w c c}w )
a/  
        Fetch a project by project_id or name.

        :param project_id: The project_id of the project to fetch.
        :type project_id: str
        :param name: The name of the project to fetch.
        :type name: str
        :return: The project.
        :rtype: Project

        Examples
        --------

        .. code-block:: python
            :caption: Fetch a project by project_id
            :emphasize-lines: 7-9

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.projects.fetch(
                project_id="42ca341d-43bf-47cb-9f27-e645dbfabea6"
            )
            print(project.id)
            print(project.name)
            print(project.max_pods)
            print(project.force_encryption_with_cmek)
            print(project.organization_id)
            print(project.created_at)

        .. code-block:: python
            :caption: Fetch a project by name
            :emphasize-lines: 7

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.projects.fetch(name="my-project-name")
            print(project.id)
            print(project.name)
            print(project.max_pods)
            print(project.force_encryption_with_cmek)
            print(project.organization_id)
            print(project.created_at)
        7Either project_id or name must be provided but not both*Either project_id or name must be providedr   r   zProject with name 'z' not found   z#Multiple projects found with name 'zL'. Please use project_id to fetch a specific project. Matching project ids: )

ValueErrorr   fetch_projectr   datar   lenr   idr   )r   r   r   projectsprojectidss         r   fetchzProjectResource.fetchQ   s   j !d&6VWWDLIJJ!%%33z3JJyy{''H/7PG7<<4;OPHP8}!'*=dV;(OPPX"19:gwzz::'9$  @L  MP  LQ  R   {" Q ;s   C0C%Cc                 (    | j                  ||      S )a  Alias for :func:`fetch`

        Examples
        --------

        .. code-block:: python
            :caption: Get a project by project_id
            :emphasize-lines: 7-9

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.project.get(
                project_id="42ca341d-43bf-47cb-9f27-e645dbfabea6"
            )
            print(project.id)
            print(project.name)
            print(project.max_pods)
            print(project.force_encryption_with_cmek)
        r   r   r(   r   r   r   s      r   getzProjectResource.get       2 zzZdz;;r   c                 (    | j                  ||      S )a  Alias for :func:`fetch`

        Examples
        --------

        .. code-block:: python
            :caption: Describe a project by project_id
            :emphasize-lines: 7-9

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.project.describe(
                project_id="42ca341d-43bf-47cb-9f27-e645dbfabea6"
            )
            print(project.id)
            print(project.name)
            print(project.max_pods)
            print(project.force_encryption_with_cmek)
        r*   r+   r,   s      r   describezProjectResource.describe   r.   r   c                     ||t        d      ||t        d      	 d|fd|fg} | j                  di t        |       y# t        $ r Y yw xY w)a  
        Check if a project exists by project_id or name.

        :param project_id: The project_id of the project to check.
        :type project_id: str
        :param name: The name of the project to check.
        :type name: str
        :return: True if the project exists, False otherwise.
        :rtype: bool

        :raises ValueError: If both project_id and name are provided.

        Examples
        --------

        .. code-block:: python
            :caption: Check if a project exists by project name
            :emphasize-lines: 8

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project_name = "my-project-name"
            if admin.project.exists(name=project_name):
                print(f"Project {project_name} exists")
            else:
                admin.project.create(
                    name=project_name,
                    max_pods=10,
                    force_encryption_with_cmek=False
                )

        .. code-block:: python
            :caption: Check if a project exists by project_id
            :emphasize-lines: 8

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project_id = "42ca341d-43bf-47cb-9f27-e645dbfabea6"
            if admin.project.exists(project_id=project_id):
                print(f"Project {project_id} exists")
            else:
                print(f"Project {project_id} does not exist")
        r   r   r   r   TF )r    r(   r   r   )r   r   r   argss       r   existszProjectResource.exists   sv    j !d&6VWWDLIJJ	!:.?DDJJ4-d34  		s   #A 	AAmax_podsforce_encryption_with_cmekc                 x    d|fd|fd|fg}t        di t        |      }| j                  j                  |      S )ax  
        Create a project.

        :param name: The name of the project to create.
        :type name: str
        :param max_pods: The maximum number of pods for the project.
        :type max_pods: int
        :param force_encryption_with_cmek: Whether to force encryption with CMEK.
        :type force_encryption_with_cmek: bool
        :return: The created project.
        :rtype: Project

        Examples
        --------

        .. code-block:: python
            :caption: Create a project
            :emphasize-lines: 7-11

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.project.create(
                name="my-project-name",
                max_pods=10,
                force_encryption_with_cmek=False
            )

            print(project.id)
            print(project.name)
            print(project.organization_id)
            print(project.max_pods)
            print(project.force_encryption_with_cmek)
            print(project.created_at)

        r   r5   r6   )create_project_requestr2   )r
   r   r   create_project)r   r   r5   r6   r3   create_requests         r   createzProjectResource.create  sS    ^ TN")+EF

 .K0DT0JK!!000WWr   c                 z    d|fd|fd|fg}t        di t        |      }| j                  j                  ||      S )a  
        Update a project.

        :param project_id: The project_id of the project to update.
        :type project_id: str
        :param name: The name of the project to update.
        :type name: str
        :param max_pods: The maximum number of pods for the project.
        :type max_pods: int
        :param force_encryption_with_cmek: Whether to force encryption with CMEK.
        :type force_encryption_with_cmek: bool
        :return: The updated project.
        :rtype: Project

        Examples
        --------

        .. code-block:: python
            :caption: Update a project by project_id
            :emphasize-lines: 10-13, 16-19

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.project.get(name='my-project-name')

            # Update max pods to 10
            project = admin.project.update(
                project_id=project.id,
                max_pods=10
            )

            # Update force_encryption_with_cmek to True
            project = admin.project.update(
                project_id=project.id,
                force_encryption_with_cmek=True
            )

        r   r5   r6   )r   update_project_requestr2   )r   r   r   update_project)r   r   r   r5   r6   r3   update_requests          r   updatezProjectResource.updateG  s\    f TN")+EF

 .K0DT0JK!!00!. 1 
 	
r   delete_all_indexesdelete_all_collectionsdelete_all_backupsc                 D   | j                  |      }|s |s|s| j                  j                  |      S ddlm}  || j
                        }t        j                  d|j                          |j                  |j                  ddg      }|j                  }		 dd	lm}
 d
}d}|s|dk  r |
|	      }|r|j                          |r|j                          |r|j                          |j!                          }|dz  }|sNt        j                  d|j                   dt#        |j$                         d       t'        j(                  d       |s|dk  rt        j                  d|j                          |j+                  |j,                  j                         t        j/                  d|        | j                  j                  |      S # t        j                  d|j                          |j+                  |j,                  j                         w xY w)a	  

        .. warning::
            Deleting a project is a permanent and irreversible operation.
            Please be very sure you want to delete the project and everything
            associated with it before calling this function.


        Projects can only be deleted if they are empty. The delete operation
        will fail if the project contains any resources such as indexes,
        collections, or backups.

        If you pass additional options such as ``delete_all_indexes=True``,
        ``delete_all_collections=True``, or ``delete_all_backups=True``, this function
        will attempt to delete all of these resources before deleting the project itself.
        **These deletions are permanent and cannot be undone.**

        :param project_id: The project_id of the project to delete.
        :type project_id: str
        :param delete_all_indexes: Attempt to delete all indexes associated with the project.
        :type delete_all_indexes: bool
        :param delete_all_collections: Attempt to delete all collections associated with the project.
        :type delete_all_collections: bool
        :param delete_all_backups: Attempt to delete all backups associated with the project.
        :type delete_all_backups: bool
        :return: ``None``

        Examples
        --------

        .. code-block:: python
            :caption: Delete a project by project_id
            :emphasize-lines: 9

            from pinecone import Admin

            # Credentials read from PINECONE_CLIENT_ID and
            # PINECONE_CLIENT_SECRET environment variables
            admin = Admin()

            project = admin.project.get(name='my-project-name')

            admin.project.delete(project_id=project.id)

        .. code-block:: python
            :caption: Delete a project that still contains indexes, collections, and backups
            :emphasize-lines: 7-12

            from pinecone import Admin

            admin = Admin()

            project = admin.project.get(name='my-project-name')

            admin.project.delete(
                project_id=project.id,
                delete_all_indexes=True,
                delete_all_collections=True,
                delete_all_backups=True
            )

            if not admin.project.exists(project_id=project.id):
                print("Project deleted successfully")
            else:
                print("Project deletion failed")
        r   r   )ApiKeyResourcez+Creating API key 'cleanup-key' for project zcleanup-keyProjectEditor)r   r   roles   )_ProjectEraserFr      )api_keyz+Retrying deletion of resources for project z. There were z undeleteable resources   z+Deleting API key 'cleanup-key' for project )
api_key_idzDeleting project )r-   r   delete_projectrK   rE   r   loggerdebugr$   r;   valueeraser.project_eraserrI   rB   rC   rA   retry_neededr#   undeleteable_resourcestimesleepdeletekeyinfo)r   r   rA   rB   rC   r&   rE   api_key_resourcekey_create_responserK   rI   doneretriesproject_erasers                 r   rW   zProjectResource.delete  s   T ((j(1"&<@R%%44
4KK+)$*:*:;B7::,OP.55zzo=N 6 
 &++	K>DGw{!/!@)"99;%"557%"557)66881LLEgjj\Q^_bcq  dI  dI  `J  _K  Kb  c JJrN! w{$ LLFwzzlST##/B/F/F/I/I#J'
|45!!00J0GG	 LLFwzzlST##/B/F/F/I/I#Js   B=G A
H)NN)NNN)FFF)__name__
__module____qualname____doc__r   r   r	   r   r   strr(   r-   r0   r4   intboolr;   r@   rW   r2   r   r   r   r      s   0&9 & 2 26 F# F#HSM F# F#P <hsm <(3- < <4 <8C= <x} < <4 ># >Xc] > >@  #'59	3X3X 3-3X %-TN	3X 3Xj  #"&599
9
 sm9
 3-	9

 %-TN9
 9
v  $)',#(sHsH !sH !%	sH
 !sH sHr   r   )typingr   pinecone.exceptionsr   r   pinecone.openapi_supportr    pinecone.core.openapi.admin.apisr   pinecone.utilsr   r	   "pinecone.core.openapi.admin.modelsr
   r   loggingrU   	getLoggerr_   rO   r   r2   r   r   <module>rn      s=     D . 8 ? Y  			8	$jH jHr   