
    @6i'                         d Z ddlmZ ddlmZ dedeeef   fdZedefd       Zedefd       Zedefd	       Z	edefd
       Z
y)zSpain.    )Dict)	validatorvaluenumber_by_letterc                     t        |       dk7  ry| j                         } d}|j                  | d   | d         | dd z   }|j                         xr | d   |t	        |      dz     k(  S )z&Validate if the doi is a NIF or a NIE.	   FTRWAGMYFPDXBNJZSQVHLCKEr            )lenuppergetisdigitint)r   r   tablenumberss       U/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/validators/i18n/es.py_nif_nie_validationr   
   sp    
5zQKKME%E ""58U1X6qCG??EqU3w<"3D-E!EE    c                <   | rt        |       dk7  ry| j                         } d}| d   }| dd }| d   }|j                         sydt        d t	        |      D              dz  z
  dz  }|d	v rt        |      |k(  S |d
v r||   |k(  S |dv r|t        |      ||   hv S dS )a  Validate a Spanish CIF.

    Each company in Spain prior to 2008 had a distinct CIF and has been
    discontinued. For more information see [wikipedia.org/cif][1].

    The new replacement is to use NIF for absolutely everything. The issue is
    that there are "types" of NIFs now: company, person [citizen or resident]
    all distinguished by the first character of the DOI. For this reason we
    will continue to call CIFs NIFs, that are used for companies.

    This validator is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
    [2]: https://generadordni.es/

    Examples:
        >>> es_cif('B25162520')
        True
        >>> es_cif('B25162529')
        ValidationError(func=es_cif, args={'value': 'B25162529'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    r   F
JABCDEFGHIr   r
   r   
   c              3      K   | ]H  \  }}|d z  dk(  r.t        t        t        t        t        |      d z                    n
t        |       J yw)   r   N)summapr   str).0indexchars      r   	<genexpr>zes_cif.<locals>.<genexpr>A   sJ      
 t 27aCCSY]+,-SYN
s   AAABEHPSQW	CDFGJNRUV)r   r   r   r   	enumerater   )r   r   	first_chrdoi_bodycontrolress         r   es_cifr+      s    > CJ!OKKMEEaIQqzHAhG

 
  )2	
 
 	 		C F3x7""FSzW$$09[0H7s3xs,,SeSr   c                &    dddd}t        | |      S )a  Validate a Spanish NIF.

    Each entity, be it person or company in Spain has a distinct NIF. Since
    we've designated CIF to be a company NIF, this NIF is only for person.
    For more information see [wikipedia.org/nif][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal
    [2]: https://generadordni.es/

    Examples:
        >>> es_nif('26643189N')
        True
        >>> es_nif('26643189X')
        ValidationError(func=es_nif, args={'value': '26643189X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    0)LMKr   r   r   s     r   es_nifr3   P   s    4 !s5u&677r   c                :    dddd}| r| d   |v rt        | |      S y)u  Validate a Spanish NIE.

    The NIE is a tax identification number in Spain, known in Spanish
    as the NIE, or more formally the Número de identidad de extranjero.
    For more information see [wikipedia.org/nie][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/N%C3%BAmero_de_identidad_de_extranjero
    [2]: https://generadordni.es/

    Examples:
        >>> es_nie('X0095892M')
        True
        >>> es_nie('X0095892X')
        ValidationError(func=es_nie, args={'value': 'X0095892X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    r-   12)XYZr   Fr1   r2   s     r   es_nier:   n   s1    4 !s5q--"5*:;;r   c                L    t        |       xs t        |       xs t        |       S )a  Validate a Spanish DOI.

    A DOI in spain is all NIF / CIF / NIE / DNI -- a digital ID.
    For more information see [wikipedia.org/doi][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/Identificador_de_objeto_digital
    [2]: https://generadordni.es/

    Examples:
        >>> es_doi('X0095892M')
        True
        >>> es_doi('X0095892X')
        ValidationError(func=es_doi, args={'value': 'X0095892X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    )r:   r3   r+   )r   s    r   es_doir<      s     2 %=:F5M:VE]:r   N)__doc__typingr   validators.utilsr   r   r   r+   r3   r:   r<    r   r   <module>rA      s      '
Fs 
Fd38n 
F 5T# 5T 5Tp 8# 8 8: #  @ ;# ; ;r   