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_fr_questionnaire_final_v2'
    players_per_group = 2
    num_rounds = 1

    showupfee = 5

    instructions_GP_template = 'exp_e4c_fr_risk_gneezy_v2/instructions.html'
    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,
                               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()
    tc3 = models.StringField()
    tiragecolor = models.FloatField()
    colorbutton = models.IntegerField()
    colorselect = models.IntegerField()
    colorselectnn = models.StringField()
    gainrisk = models.FloatField()
    gainriskeur = models.FloatField()
    gainriskeurfinal = models.FloatField()

    q_40_etude = models.IntegerField(
        choices=[
            [1, '1- Arts et/ou littérature'],
            [2, '2- Economie et/ou gestion'],
            [3, '3- Scientifique / ingénierie'],
            [4, '4- Autre'],
        ],
        widget=widgets.RadioSelect,
        label="Votre domaine d’étude ",
        blank=False
    )

    q_41_gender = models.IntegerField(
        choices=[
            [1, '1- Femme'],
            [2, '2- Homme'],
            [3, '3- Non-binaire'],
            [4, '4- Ne souhaite pas répondre'],
        ],
        widget=widgets.RadioSelect,
        label="Vous êtes ",
        blank=False
    )

    q_42_annee_naissance = models.IntegerField(
        label="Quelle est votre année de naissance ?",
        blank=False,
        min=1900,
        max=2019)

    q_43_nationalite = models.StringField(
        label="Votre nationalité ",
        blank=False
    )

    q_44_revenu = models.IntegerField(
        choices=[
            [1, '1- Inférieur à 5 000 Euros'],
            [2, '2- Entre 5 000 et 10 000 Euros'],
            [3, '3- Entre 10 000 et 15 000 Euros '],
            [4, '4- Entre 15 000 et 20 000 Euros '],
            [5, '5- Entre 20 000 et 25 000 Euros '],
            [6, '6- Supérieur à 25 000 Euros '],
        ],
        widget=widgets.RadioSelect,
        label="Veuillez estimer votre revenu annuel brut (y compris vos bourses d'études et votre prêt étudiant) en Euros. ",
        blank=False
    )

    q_45_logement_pays = models.StringField(
        label="Ville - précédent logement  ",
        blank=False
    )

    q_46_logement_ville = models.StringField(
        label="Pays - précédent logement ",
        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()

