from math import floor
import renpy
from game.main_character.MainCharacter_ren import mc
from game.major_game_classes.character_related.Person_ren import Person

"""renpy
IF FLAG_OPT_IN_ANNOTATIONS:
    rpy python annotations
init 5 python:
"""
def kina_decorate_run_day():
    #Making it harder to increase baby desire
    undecorated_run_day = Person.run_day
    def decorated_function(self,*args,**kwargs):
        #Run the vanilla "run_day" actions.
        undecorated_run_day(self,*args,**kwargs)
        #disable the base game's changes first
        if persistent.pregnancy_pref > 2:
        #Only on realistic setting
            if self.love > self.baby_desire + 20:
                self.change_baby_desire(-1) #base game add 1 if love > 20 so we takes it back       
            #Now we update the baby desire ...
            kidsmult = self.kids * 5 #More kids, the higher happiness threshold needed to have another  
            kidsvar = self.kids * 20 #She more reluctant to have more kids if she already have several 
            if self.happiness > 140 + kidsmult:
                if self.love > self.baby_desire + kidsvar + 20:
                    self.change_baby_desire(1)
                    #mc.log_event(self.title + " dreamt of having a baby", "float_text_grey")
            elif self.happiness < 120 + kidsmult:
                if not self.has_breeding_fetish:
                    self.change_baby_desire(-1)
                    #mc.log_event(self.title + " having nightmare of getting pregnant", "float_text_grey")

            #Child Support
            if child_support_enabled and day % 7 == 5 and self.has_child_with_mc: #Saturday and mothered your childs
                amount = self.number_of_children_with_mc * cs_amount
                mc.business.change_funds(-amount, stat = "Family Support")
                if self.number_of_children_with_mc == 1:
                    mc.log_event(f"{self.name} {self.last_name} : {self.possessive_title} received ${amount} in child support for {self.number_of_children_with_mc} child.", "float_text_grey")
                else:
                    mc.log_event(f"{self.name} {self.last_name} : {self.possessive_title} received ${amount} in child support for {self.number_of_children_with_mc} children.", "float_text_grey")
                    #mc.log_event(self.name + " " + self.last_name + ", "self.possessive_title + ", received " + str(amount) + "  in child support for " + str(self.number_of_children_with_mc) + " children.", "float_text_grey")
            
        #Happiness boost. The base game normalize toward 100 which is below happiness. The only way the girls gains happiness is through interactions with player.
        #Yet, they will lose happiness especially those that had poor opinion on Friday, weekend and Monday. Thus, after 2 weeks, they falls into depression if you didnt interact with them
        if self.love > 10 and self.happiness < 130: #This allow up to 140 happiness with 100 love.
            amount = builtins.int(builtins.round(self.love/10))
            self.change_happiness(amount, add_to_log = False)
            #mc.log_event(self.title + "'s happiness buff by " + str(amount), "float_text_grey")
            
        
                
    Person.run_day = decorated_function
kina_decorate_run_day()