(2) If a court of competent jurisdiction finds that conduct in violation of subdivision d of section 27-2005 of this chapter has occurred, it may determine that a class c violation existed at the time that such conduct occurred. Notwithstanding the foregoing, such court may also issue an order restraining the owner of the property from violating such subdivision and direct the owner to ensure that no further violation occurs, in accordance with section 27-2121 of this chapter. Such court shall impose a civil penalty in an amount not less than two thousand dollars and not more than ten thousand dollars for each dwelling unit in which a tenant or any person lawfully entitled to occupancy of such unit has been the subject of such violation, and such other relief as the court deems appropriate, provided that where a petitioner establishes that there was a previous finding of a violation of subdivision d of section 27-2005 against such owner and such finding was made (i) within the preceding five year period and (ii) on or after the effective date of the local law that added this clause, such court shall impose a civil penalty in an amount not less than four thousand dollars and not more than ten thousand dollars. It shall be an affirmative defense to an allegation by a tenant of the kind described in subparagraphs b, c and g of paragraph forty-eight of subdivision a of section 27-2004 of this chapter that (i) such condition or service interruption was not intended to cause any lawful occupant to vacate a dwelling unit or waive or surrender any rights in relation to such occupancy, and (ii) the owner acted in good faith in a reasonable manner to promptly correct such condition or service interruption, including providing notice to all affected lawful occupants of such