import random
from otree.api import (
    models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
    Currency as c, currency_range
)


doc = """
Author : Wael Bousselmi 
"""

class Constants(BaseConstants):
    name_in_url = 'exp_e4c_fr_risk_binswanger_v2'
    players_per_group = 2
    num_rounds = 1

    tauxdechange = 1

    instructions_BW_template = 'exp_e4c_fr_risk_binswanger_v2/Risk_BinsWanger_qc.html'

    gainriskAred = 4
    gainriskBred = 3
    gainriskCred = 2
    gainriskDred = 1
    gainriskEred = 0

    gainriskAgreen = 4
    gainriskBgreen = 6
    gainriskCgreen = 8
    gainriskDgreen = 10
    gainriskEgreen = 12

class Subsession(BaseSubsession):

    def vars_for_admin_report(self):
        report = list()
        for p in self.get_players():
            report.append(dict(id=p.participant.id_in_session, label=p.participant.label, answers=p.gainrisk))
        return dict(report=report)


class Group(BaseGroup):
    pass


#############################
def imi_inv(label):
    return models.IntegerField(
        choices=[
            [0, '0'],
            [1, '1'],
            [2, '2'],
            [3, '3'],
            [4, '4'],
            [5, '5'],
            [6, '6'],
            [7, '7']
        ],
        label=label,
        widget=widgets.RadioSelect,
        blank=False
    )

# Define template for Goal commitment questions
def goal_com(label):
    return models.IntegerField(
        choices=[
            [0, '0'],
            [1, '1'],
            [2, '2'],
            [3, '3'],
            [4, '4'],
            [5, '5'],
        ],
        label=label,
        widget=widgets.RadioSelect,
        blank=False
    )
#############################



class Player(BasePlayer):

    riskqc_a = models.IntegerField(
        choices=[
            [1, '6 ECUs'],
            [2, '0 ECUs'],
            [3, '2 ECUs'],
            [4, '3 ECUs'],
        ],
        label="",
        widget=widgets.RadioSelectHorizontal,
        blank=False
    )

    riskqc_b = models.IntegerField(
        choices=[
            [1, '10 ECUs'],
            [2, '0 ECUs'],
            [3, '1 ECU'],
            [4, '6 ECUs'],
        ],
        label="",
        widget=widgets.RadioSelectHorizontal,
        blank=False
    )

    riskqc_c = models.IntegerField(
        choices=[
            [1, '0 ECUs'],
            [2, '1 ECU'],
            [3, '12 ECUs'],
            [4, '4 ECUs'],
        ],
        label="",
        widget=widgets.RadioSelectHorizontal,
        blank=False
    )

    choicerisk = models.IntegerField(
        blank=False,
    )

    choicerisknn = models.StringField()

    tc3 = models.StringField()
    tiragecolor = models.FloatField()
    colorbutton = models.IntegerField()

    colorselect = models.IntegerField()
    colorselectnn = models.StringField()
    gainrisk = models.FloatField()
    gainriskeur = models.FloatField()
    gainriskeurfinal = models.FloatField()

    task_start_risk = models.FloatField()
    task_time_risk = models.FloatField()










