
    \j!                     d    d dl Z d dlZd dlmZmZmZ  G d d      Z G d d      Z G d d      Zy)	    N)AnyDictOptionalc                       e Zd ZdZdedee   defdZe	defd       Z
e	dee   fd       Ze	defd	       Zdefd
ZdefdZdefdZdefdZdefdZy)EvaluationDetailz
    The return type of :func:`ldclient.client.LDClient.variation_detail()`, combining the result of a
    flag evaluation with information about how it was calculated.
    valuevariation_indexreasonc                 .    || _         || _        || _        y)z Constructs an instance.
        N)_EvaluationDetail__value"_EvaluationDetail__variation_index_EvaluationDetail__reason)selfr   r	   r
   s       =/root/env/lib/python3.12/site-packages/ldclient/evaluation.py__init__zEvaluationDetail.__init__
   s     !0    returnc                     | j                   S )zThe result of the flag evaluation. This will be either one of the flag's
        variations or the default value that was passed to the
        :func:`ldclient.client.LDClient.variation_detail()` method.
        )r   r   s    r   r   zEvaluationDetail.value   s     ||r   c                     | j                   S )zThe index of the returned value within the flag's list of variations, e.g.
        0 for the first variation -- or None if the default value was returned.
        r   r   s    r   r	   z EvaluationDetail.variation_index   s    
 %%%r   c                     | j                   S )a
  A dictionary describing the main factor that influenced the flag evaluation value.
        It contains the following properties:

        * ``kind``: The general category of reason, as follows:

          * ``"OFF"``: the flag was off
          * ``"FALLTHROUGH"``: the flag was on but the user did not match any targets or rules
          * ``"TARGET_MATCH"``: the user was specifically targeted for this flag
          * ``"RULE_MATCH"``: the user matched one of the flag's rules
          * ``"PREREQUISITE_FAILED"``: the flag was considered off because it had at least one
            prerequisite flag that did not return the desired variation
          * ``"ERROR"``: the flag could not be evaluated due to an unexpected error.

        * ``ruleIndex``, ``ruleId``: The positional index and unique identifier of the matched
          rule, if the kind was ``RULE_MATCH``

        * ``prerequisiteKey``: The flag key of the prerequisite that failed, if the kind was
          ``PREREQUISITE_FAILED``

        * ``errorKind``: further describes the nature of the error if the kind was ``ERROR``,
          e.g. ``"FLAG_NOT_FOUND"``
        
        * ``bigSegmentsStatus``: describes the validity of Big Segment information, if and only if
          the flag evaluation required querying at least one Big Segment; otherwise it returns None.
          Allowable values are defined in :class:`BigSegmentsStatus`. For more information, read the
          LaunchDarkly documentation: https://docs.launchdarkly.com/home/users/big-segments
        )r   r   s    r   r
   zEvaluationDetail.reason    s    : }}r   c                     | j                   du S )zkReturns True if the flag evaluated to the default value rather than one of its
        variations.
        Nr   r   s    r   is_default_valuez!EvaluationDetail.is_default_value?   s     %%--r   c                     | j                   |j                   k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S Nr   r	   r
   r   others     r   __eq__zEvaluationDetail.__eq__E   sC    zzU[[(zT-A-AUEZEZ-Zz_c_j_jnsnznz_zzr   c                 &    | j                  |       S r   )r    r   s     r   __ne__zEvaluationDetail.__ne__H   s    ;;u%%%r   c                 V    d| j                   d| j                  d| j                  dS )Nz(value=z, variation_index=z	, reason=)r   r   s    r   __str__zEvaluationDetail.__str__K   s     >Bjj$J^J^`d`k`kllr   c                 "    | j                         S r   )r%   r   s    r   __repr__zEvaluationDetail.__repr__N   s    ||~r   N)__name__
__module____qualname____doc__objectr   intdictr   propertyr   r	   r
   boolr   r    r"   strr%   r'    r   r   r   r      s    f x} d  v   &# & &   <.$ .{t {&t &m m# r   r   c                   &    e Zd ZdZdZ	 dZ	 dZ	 dZy)BigSegmentsStatusz
    Indicates that the Big Segment query involved in the flag evaluation was successful, and
    the segment state is considered up to date.
    HEALTHYSTALENOT_CONFIGUREDSTORE_ERRORN)r(   r)   r*   r+   r5   r6   r7   r8   r2   r   r   r4   r4   R   s2     G E &N  Kr   r4   c                       e Zd ZdZdefdZd Zedefd       Zde	de
fdZde	dee   fd	Zdefd
ZdefdZde	fdZdefdZy)FeatureFlagsStatea  
    A snapshot of the state of all feature flags with regard to a specific user, generated by
    calling the :func:`ldclient.client.LDClient.all_flags_state()` method. Serializing this
    object to JSON, using the :func:`to_json_dict` method or ``jsonpickle``, will produce the
    appropriate data structure for bootstrapping the LaunchDarkly JavaScript client. See the
    JavaScript SDK Reference Guide on `Bootstrapping <https://docs.launchdarkly.com/sdk/features/bootstrapping#javascript>`_.
    validc                 .    i | _         i | _        || _        y r   )_FeatureFlagsState__flag_values!_FeatureFlagsState__flag_metadata_FeatureFlagsState__valid)r   r;   s     r   r   zFeatureFlagsState.__init__t   s    !r   c                    |d   }|d   | j                   |<   i }|j                  dd      }|j                  dd      }d}|r?t        t        j                         dz        }	|s|s|j                  d      |d   |	kD  sd}|s|sd n|d	   }
|
|s|
|d	<   |s|d
   |d
<   |d   |d   |d<   |rd|d<   |rd|d<   |j                  d      |j                  d      |d<   || j                  |<   y )Nkeyr   trackEventsFtrackReasoni  debugEventsUntilDateTr
   version	variation)r=   getr-   timer>   )r   
flag_statewith_reasonsdetails_only_if_trackedrA   metarB   rC   omit_detailsnowr
   s              r   add_flagzFeatureFlagsState.add_flagz   s6   ",W"53 nn]E: nn]E:"diikD()C{JNNKa<b<ns}  U  tV  Y\  t\#)+:hCWl#DN(3DOk". *; 7D"&D"&D>>01=+5>>:P+QD'($(S!r   r   c                     | j                   S )zTrue if this object contains a valid snapshot of feature flag state, or False if the
        state could not be computed (for instance, because the client was offline or there was no user).
        )r?   r   s    r   r;   zFeatureFlagsState.valid   s    
 ||r   rA   c                 8    | j                   j                  |      S )zReturns the value of an individual feature flag at the time the state was recorded.

        :param key: the feature flag key
        :return: the flag's value; None if the flag returned the default value, or if there was no such flag
        )r=   rG   )r   rA   s     r   get_flag_valuez FeatureFlagsState.get_flag_value   s     !!%%c**r   c                 b    | j                   j                  |      }|dS |j                  d      S )a  Returns the evaluation reason for an individual feature flag at the time the state was recorded.

        :param key: the feature flag key
        :return: a dictionary describing the reason; None if reasons were not recorded, or if there was no
          such flag
        Nr
   )r>   rG   )r   rA   rL   s      r   get_flag_reasonz!FeatureFlagsState.get_flag_reason   s2     ##'',|t;();;r   c                     | j                   S )a-  Returns a dictionary of flag keys to flag values. If the flag would have evaluated to the
        default value, its value will be None.

        Do not use this method if you are passing data to the front end to "bootstrap" the JavaScript client.
        Instead, use :func:`to_json_dict()`.
        )r=   r   s    r   to_values_mapzFeatureFlagsState.to_values_map   s     !!!r   c                 v    | j                   j                         }| j                  |d<   | j                  |d<   |S )zReturns a dictionary suitable for passing as JSON, in the format used by the LaunchDarkly
        JavaScript SDK. Use this method if you are passing data to the front end in order to
        "bootstrap" the JavaScript client.
        z$flagsStatez$valid)r=   copyr>   r?   )r   rets     r   to_json_dictzFeatureFlagsState.to_json_dict   s:    
   %%'!11MH
r   c                 H    t        j                  | j                               S )zOSame as to_json_dict, but serializes the JSON structure into a string.
        )jsondumpsrZ   r   s    r   to_json_stringz FeatureFlagsState.to_json_string   s     zz$++-..r   c                 "    | j                         S )z_Equivalent to to_json_dict() - used if you are serializing the object with jsonpickle.
        )rZ   r   s    r   __getstate__zFeatureFlagsState.__getstate__   s       ""r   N)r(   r)   r*   r+   r0   r   rO   r/   r;   r1   r,   rR   r   r.   rT   rV   rZ   r^   r`   r2   r   r   r:   r:   l   s    d )@ t  +# +& +<3 <8D> <"t "d / /
#d #r   r:   )	r\   rH   typingr   r   r   r   r4   r:   r2   r   r   <module>rb      s4      & &J JZ   4c# c#r   