from policyengine_us.model_api import *


class il_pi_is_poverty(Variable):
    value_type = bool
    entity = Person
    label = "Experiencing poverty for Illinois PI (Factor 36, 10 points)"
    definition_period = YEAR
    reference = (
        "https://www.isbe.net/Documents/Prevention-Initiative-Eligibility-Form.pdf#page=3",
    )
    defined_for = StateCode.IL

    def formula(person, period, parameters):
        spm_unit = person.spm_unit
        # Factor 36 (10 pts): Child/Family experiencing poverty (200% FPL).
        p = parameters(period).gov.states.il.isbe.pi.eligibility.income
        fpg = spm_unit("spm_unit_fpg", period)
        income = spm_unit("il_isbe_countable_income", period)
        threshold = fpg * p.poverty_rate
        return income <= threshold
