from fiscalsim_us.model_api import *


class ctc_child_individual_maximum(Variable):
    value_type = float
    entity = Person
    label = "CTC maximum amount (child)"
    unit = USD
    documentation = "The CTC entitlement in respect of this person as a child."
    definition_period = YEAR
    reference = (
        "https://www.law.cornell.edu/uscode/text/26/24#a",
        "https://www.law.cornell.edu/uscode/text/26/24#h",
        "https://www.law.cornell.edu/uscode/text/26/24#i",
    )

    def formula(person, period, parameters):
        age = person("age", period)
        base_amount = parameters(period).gov.irs.credits.ctc.amount.base
        is_dependent = person("is_tax_unit_dependent", period)
        return base_amount.calc(age) * is_dependent
