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

doc = """
author = 'Wael Bousselmi'
Exp E4C
"""


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

    showupfee = 5

    instructions_GP_template = 'exp_e4c_en_p2_risk_gneezy/instructions.html'
    instructions_BW_template = 'exp_e4c_en_p5_questfin/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,
                               jeu_tire=p.jeu_tire,
                               gainfinal=p.gainfinal,
                               gainfinalplushowup=p.gainfinalplushowup,
                               ))
        return dict(report=report)

class Group(BaseGroup):
    pass

class Player(BasePlayer):
    langue = models.StringField()
    langue_nn = models.IntegerField()

    def role(self):
        return {1: 'A', 2: 'B'}[self.id_in_group]

#########  var jeu Binswanger
    choicerisk = models.IntegerField(
        blank=False,
    )

    choicerisknn = models.StringField() ### jeu 1 : Binswanger
    tc3 = models.StringField()
    tiragecolor = models.FloatField()
    colorbutton = models.IntegerField()
    colorselect = models.IntegerField() ### jeu 1 : Binswanger
    colorselectnn = models.StringField()
    gainrisk = models.FloatField() ### jeu 1 : Binswanger
    gainriskeur = models.FloatField() ### jeu 1 : Binswanger
    gainriskeurfinal = models.FloatField()

    q_40_etude = models.IntegerField(
        choices=[
            [1, '1- Arts and / or literature'],
            [2, '2- Economy and / or management'],
            [3, '3- Scientific / engineering'],
            [4, '4- Other'],
        ],
        widget=widgets.RadioSelect,
        label="Your field of study  ",
        blank=False
    )

    q_41_gender = models.IntegerField(
        choices=[
            [1, '1- Woman'],
            [2, '2- Male'],
            [3, '3- Non-binary'],
            [4, '4- Do not wish to answer'],
        ],
        widget=widgets.RadioSelect,
        label="You are ",
        blank=False
    )


    q_42_annee_naissance = models.IntegerField(
        label="What is your year of birth?",
        blank=False,
        min=1900,
        max=2019
    )

    q_43_nationalite = models.StringField(
        label="Your nationality",
        blank=False
    )

    q_44_revenu = models.IntegerField(
        choices=[
            [1, '1- Less than 5,000 Euros'],
            [2, '2- Between 5,000 and 10,000 Euros'],
            [3, '3- Between 10,000 and 15,000 Euros'],
            [4, '4- Between 15,000 and 20,000 Euros'],
            [5, '5- Between 20,000 and 25,000 Euros'],
            [6, '6- Greater than 25,000 Euros'],
            ],
        widget=widgets.RadioSelect,
        label="Please estimate your gross annual income (including your scholarships and student loan) in Euros.",
        blank=False
    )

    q_45_logement_pays = models.StringField(
        label="City - previous accommodation",
        blank=False
    )

    q_46_logement_ville = models.StringField(
        label="Country - previous accommodation",
        blank=False
    )


### jeu 2 : Gneezy&Potters
    tirageriskresult_j1  = models.StringField()
    risk11_a_j1 = models.FloatField()
    risk11_b_j1 = models.FloatField()
    gainrisk_j1 = models.FloatField()


    tirageausort = models.FloatField()

    gainfinal = models.FloatField()
    jeu_tire = models.IntegerField()
    gainfinalecu = models.FloatField()
    gainfinalplushowup = models.FloatField()

