Ë
    Ìi…  ã                   ó°   — d dl Z d dlmZmZ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mZmZmZmZ  e j&                  e«      Z G d„ dee   ee   «      Zy)	é    N)ÚGenericÚListÚSequence)ÚSemanticManifestTÚSemanticModel)ÚSemanticModelReference)Ú
EntityType)ÚFileContextÚSemanticManifestValidationRuleÚSemanticModelContextÚValidationErrorÚValidationIssueÚvalidate_safelyc                   ó–   — e Zd ZdZededefd„«       Ze ed«      dede	e
   fd„«       «       Ze ed«      dede	e
   fd	„«       «       Zy
)ÚPrimaryEntityRuleah  Checks that the primary entity has been properly defined in a semantic model.

    * If a semantic model contains dimensions, the primary entity must be available.
    * The primary entity could be defined by the primary_entity field, or by one of the entities defined in a semantic
      model.
    * There should only be one primary entity in the model.
    Úsemantic_modelÚreturnc                 ó2   — t        | j                  «      dkD  S )Nr   )ÚlenÚ
dimensions)r   s    ús/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt_semantic_interfaces/validations/primary_entity.pyÚ_model_requires_primary_entityz0PrimaryEntityRule._model_requires_primary_entity   s   € ä�>×,Ñ,Ó-°Ñ1Ð1ó    zECheck that a semantic model has properly configured primary entities.c           
      óØ  — t        t        j                  | j                  ¬«      t	        | j
                  ¬«      ¬«      }t        d„ | j                  D «       «      }t        |«      dkD  r±t        |«      dkD  rR|D �cg c]  }|j
                  ‘Œ }}t        d| j
                  › dt        |«      › d	d
j                  |«      › �|¬«      fS |d   }| j                  �@t        d| j
                  › d|j
                  › d| j                  j                  › d�|¬«      fS t        j                  | «      r6| j                  €*t        |«      dk(  rt        d| j
                  › d�|¬«      fS yc c}w )N)Úmetadata)Úsemantic_model_name)Úfile_contextr   c              3   óZ   K  — | ]#  }|j                   t        j                  u sŒ |–— Œ% y ­w©N)Útyper	   ÚPRIMARY)Ú.0Úentitys     r   ú	<genexpr>z1PrimaryEntityRule._check_model.<locals>.<genexpr>)   s&   è ø€ ò +
Ø¸F¿K¹KÌ:×K]ÑK]Ò<]ŒFñ+
ùs   ‚!+¤+r   é   zFSemantic models can have only one primary entity. The semantic model `z` has z: z, )ÚmessageÚcontextzThe semantic model `z` has an entity named `zG` with type primary but it also has the `primary_entity` field set to `z+`. Both should not be present in the model.zThe semantic model z� contains dimensions, but it does not define a primary entity. Either add an entity with type PRIMARY or set a value for the primary_entity key.© )r   r
   Úfrom_metadatar   r   ÚnameÚtupleÚentitiesr   r   ÚjoinÚprimary_entity_referenceÚelement_namer   r   )r   r'   Úentities_with_primary_typeÚprimary_entityÚprimary_entity_namesÚentity_with_primary_types         r   Ú_check_modelzPrimaryEntityRule._check_model    s±  € ô 'Ü$×2Ñ2¸N×<SÑ<SÔTÜ1Àn×FYÑFYÔZô
ˆô &+ñ +
Ø!/×!8Ñ!8ô+
ó &
Ð"ô Ð)Ó*¨QÒ.ÜÐ-Ó.°Ò2ØRlÖ'mÀ¨×(;Ó(;Ð'mÐ$Ð'mä#ð!Ø!/×!4Ñ!4Ð 5°V¼CÐ@TÓ<UÐ;VÐVXØ#Ÿy™yÐ)=Ó>Ð?ðAð !(ôð	ð 	ð (BÀ!Ñ'DÐ$à×6Ñ6ÐBä#à2°>×3FÑ3FÐ2Gð H Ø 8× =Ñ =Ð>ð ?-Ø-;×-TÑ-T×-aÑ-aÐ,bð c7ð8ð
 !(ôð
ð 
ô ×<Ñ<¸^ÔLØ×7Ñ7Ð?ÜÐ.Ó/°1Ò4ô  à-¨n×.AÑ.AÐ-Bð C.ð /ð $ôð	ð 	ð ùòY (ns   Á<E'zUCheck that semantic models in the manifest have properly configured primary entities.Úsemantic_manifestc                 ó\   — g }| j                   D ]  }|t        j                  |«      z  }Œ |S r   )Úsemantic_modelsr   r4   )r5   Úissuesr   s      r   Úvalidate_manifestz#PrimaryEntityRule.validate_manifest]   s=   € ð )+ˆØ/×?Ñ?ò 	EˆNØÔ'×4Ñ4°^ÓDÑD‰Fð	Eð ˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   Úboolr   r   r   r   r4   r   r9   r(   r   r   r   r      s—   „ ñð ð2°}ð 2Èò 2ó ð2ð ÙÐ\Ó]ð9 ]ð 9°xÀÑ7Pò 9ó ^ó ð9ðv ÙÐlÓmðÐ->ð À8ÈOÑC\ò ó nó ñr   r   )ÚloggingÚtypingr   r   r   Ú!dbt_semantic_interfaces.protocolsr   r   Ú"dbt_semantic_interfaces.referencesr   Ú"dbt_semantic_interfaces.type_enumsr	   Ú5dbt_semantic_interfaces.validations.validator_helpersr
   r   r   r   r   r   Ú	getLoggerr:   Úloggerr   r(   r   r   ú<module>rH      sR   ðÛ ß *Ñ *ç NÝ EÝ 9÷÷ ð 
ˆ×	Ñ	˜8Ó	$€ôQÐ6Ð7HÑIÈ7ÐSdÑKeõ Qr   