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


doc = """
This is the gamified version of the dictator game + trust game with the strategy method
"""


class Constants(BaseConstants):
    name_in_url = 'PSE'
    players_per_group = None
    num_rounds = 1

    c_orders = ["Dictator_Trust", "Trust_Dictator"]
    c_matchings = ["Same_Class", "Other_Class"]
    c_nb_match_other_class = 10

    c_france = 'fr'
    c_england = 'en'
    c_spain = 'es'
    c_greece = 'gr'


class Subsession(BaseSubsession):
    def creating_session(self):
        # Initialise subsession variables
        if self.round_number == 1:
            # Create the necessary session variables
            pass
        for g in self.get_groups():
            # Initialise groups variables
            type_matching = itertools.cycle(Constants.c_matchings)
            for p in g.get_players():
                # Initialise players variables
                p.matched_with = next(type_matching)
                p.games_order = Constants.c_orders[np.random.randint(2)]


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    # Variables for XP mechanics
    games_order = models.StringField(initial=Constants.c_orders[0])
    matched_with = models.StringField(initial=Constants.c_matchings[0])
    with_anim = models.BooleanField(initial=True)
    country = models.StringField(initial="not initialised")
    # Variables for player's answers
    choco_send_dictator = models.IntegerField(
        min=0, max=10,
        verbose_name="")
    choco_send_trust = models.IntegerField(
        min=0, max=5,
        verbose_name="")
    choco_send_back_trust_1 = models.IntegerField(
        min=0, max=3,
        verbose_name="")
    choco_send_back_trust_2 = models.IntegerField(
        min=0, max=6,
        verbose_name="")
    choco_send_back_trust_3 = models.IntegerField(
        min=0, max=9,
        verbose_name="")
    choco_send_back_trust_4 = models.IntegerField(
        min=0, max=12,
        verbose_name="")
    choco_send_back_trust_5 = models.IntegerField(
        min=0, max=15,
        verbose_name="")
