"""
Created on: Wed Oct 13 19:43:59 2021
Author: vila@cs.upc.edu
"""
def ebill_check(GasP, REP, Consum, Day):
    Iserr, err = False, 0
    if GasP < 0.0 or REP < 0.0 or Consum < 0:
        Iserr, err = True, 100
    if Consum <= 0:
        Iserr, err = True, err+10
    if not (1 <= Day <= 7):
        Iserr, err = True, err+1
        
    return Iserr, err


def ebill_eval(GasP, REP, Consum, Day):
    if GasP > REP*2:
        preu = GasP + REP
        pp = Consum * preu
        if Consum > 100:
            pp *= 0.75
        elif Consum >= 10:
            pp *= 0.90
        else:
            pass
    else:
        preu = max(GasP, REP)
        pp = Consum * preu
        if Consum > 100:
            pp *= 0.85
    if Day == 6 or Day == 7:
        pp *= 0.5
        
    return int(pp)


def ebill_calc(GasP, REP, Consum, Day):
    Iserr, err = ebill_check(GasP, REP, Consum, Day)
    if Iserr:
        return True, err
    else:
        return False, ebill_eval(GasP, REP, Consum, Day)
