
    soj,                        d dl mZ d dlmZ d dlmZ d dlmZ d dl	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mZmZ d dlmZ dedee         fdZdededefdZ	 	 ddededededdf
dZdedefdZ dede!fdZ"dS )    N)DevilFruitAbility)IncomeTaxEvent)User)DevilFruitAbilityType)IncomeTaxBracket)IncomeTaxBreakdown)IncomeTaxContributionTypeIncomeTaxContribution)IncomeTaxDeductionIncomeTaxDeductionType)get_cumulative_percentage_sumget_value_from_percentage)object_to_json_stringuserreturnc                    g }| j         r/|                    t          t          j        d                     |S |                                 r/|                    t          t          j        d                     |S t          j        | t          j
                  }|2|                    t          t          j        |j                             |S )z\
    Get the deductions of a user
    :param user: The user
    :return: The deductions
    d   )is_adminappendr   r   ADMINis_legendary_pirateLEGENDARY_PIRATEr   get_user_abilityr   
INCOME_TAXDEVIL_FRUITvalue)r   
deductionstax_abilitys      &/app/src/service/income_tax_service.pyget_tax_deductionsr       s     ,.J } ,-C-I3OOPPP !! ,-C-TVYZZ[[[ &7%G#.& &K 5A;CTUU	
 	
 	
     amountc                     t          j        | j        |          }t          j        |          }|dk    r|S t          |           }|dk    rdS |t          ||          z  }t          |          S )z{
    Get the tax amount for a user
    :param user: The user
    :param amount: The amount
    :return: The tax amount
    r   r   )r   get_tax_breakdowntotal_gained_bountyr   get_amount_from_list'get_tax_deduction_cumulative_percentager   int)r   r"   tax_breakdowntotal_tax_amounttax_deduction_percentages        r   get_tax_amountr,   3   s     %6t7OQWXXM)>}MM1  GtLL3&&q12BD\]]]    r!   contribution_type
tax_amount	tax_eventc                    ddl m} ||t          d          |	||j        }| t          j        k    rHt          j                                        }t          ||          } ||t          |                     n	 t          d|            |dS t          | |          }t          j        |j                  }|                    |           t          |          |_        |                                 dS )z
    Add a tax contribution

    :param contribution_type: The contribution type
    :param tax_amount: The tax amount
    :param tax_event: The tax event
    :param user: The user
    :return: None
    r   )add_to_crew_chestNz)Either tax_event or user must be providedzInvalid contribution type: )src.service.crew_servicer1   
ValueErrorr   r	   
CREW_CHESTEnvTAX_CREW_CHEST_PERCENTAGE	get_floatr   r(   r
   from_stringcontribution_listr   r   save)	r-   r.   r/   r   r1   contribution_percentagecontribution_amountcontributionr9   s	            r   add_contributionr>   L   s-    ;:::::T\DEEE~
&111&)&C&M&M&O&O#";JH_"`"`dC(;$<$<====N;LNNOOO +@2+ +L
 6K5V#6 6 \*** #88I"J"JINNr!   c                 |    t          |           }t          |          dk    rdS t          d |D                       S )z~
    Get the cumulative percentage of all tax deductions
    :param user: The user
    :return: The cumulative percentage
    r   c                     g | ]	}|j         
S  )
percentage).0	deductions     r   
<listcomp>z;get_tax_deduction_cumulative_percentage.<locals>.<listcomp>   s    )[)[)[9)*>)[)[)[r!   )r    lenr   )r   r   s     r   r'   r'   ~   sE     $D))J
:!q()[)[PZ)[)[)[\\\r!   c                 (    t          |           dk    S )z
    Check if a user has a complete deduction
    :param user: The user
    :return: True if the user has a complete deduction, False otherwise
    r   )r'   )r   s    r   user_has_complete_tax_deductionrH      s     3488C??r!   )NN)#resources.EnvironmentEnvironmentr5   src.model.DevilFruitAbilityr   src.model.IncomeTaxEventr   src.model.Userr   1src.model.enums.devil_fruit.DevilFruitAbilityTyper   +src.model.enums.income_tax.IncomeTaxBracketr   -src.model.enums.income_tax.IncomeTaxBreakdownr   0src.model.enums.income_tax.IncomeTaxContributionr	   r
   -src.model.enums.income_tax.IncomeTaxDeductionr   r   src.utils.math_utilsr   r   src.utils.string_utilsr   listr    r(   r,   r>   floatr'   boolrH   rA   r!   r   <module>rX      s   # # # # # # 9 9 9 9 9 9 3 3 3 3 3 3       S S S S S S H H H H H H L L L L L L               Z Y Y Y Y Y Y Y 8 8 8 8 8 8T d+=&>    >! !s !s ! ! ! !8 !%	/ /0// / 	/
 
/ / / /d]$ ]5 ] ] ] ]@$ @4 @ @ @ @ @ @r!   