from otree.api import (
    models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
)
import random

author = 'MTurk Requester'

doc = """
urns_
"""

class Constants(BaseConstants):
    name_in_url = 'urnsT'
    players_per_group = None
    tasks = ['PageOneT', 'PageTwoT', 'PageFourT']
    num_rounds = len(tasks)+1
    instructions_template = 'urns2/InstructionsT.html'


class Subsession(BaseSubsession):
    def creating_session(self):
        if self.round_number == 2:
            for p in self.get_players():
                round_numbers = list(range(2, Constants.num_rounds+1))
                random.shuffle(round_numbers)
                p.participant.vars['task_rounds_urn2'] = dict(zip(['PageOneT', 'PageTwoT', 'PageFourT'], round_numbers))


class Group(BaseGroup):
    pass


class Player(BasePlayer):

    def true_false_1_choices(self):
        choices = ['True', 'False']
        random.shuffle(choices)
        return choices

    def true_false_2_choices(self):
        choices = ['True', 'False']
        random.shuffle(choices)
        return choices

    def true_false_3_choices(self):
        choices = ['True', 'False']
        random.shuffle(choices)
        return choices

    def true_false_7_choices(self):
        choices = ['True', 'False']
        random.shuffle(choices)
        return choices

    def urn_choice_red_2_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_blue_2_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_red_3_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_blue_3_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_red_4_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_blue_4_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_2_R_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_2_B_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_3_RR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_3_RB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_3_BR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_3_BB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_RRR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_BBB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_RRB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_BBR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_RBR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_BRB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_BRR_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def social_info_4_RBB_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_position1_red_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def urn_choice_position1_blue_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def information_channel_2_choices(self):
        choices = ['Draw a ball from the actual urn selected for your 4-member group in this round',
                   'See the group urn guess by the player in position 1']
        random.shuffle(choices)
        return choices

    def information_channel_3_choices(self):
        choices = ['Draw a ball from the actual urn selected for your 4-member group in this round',
                   'See the respective group urn guesses by players in position 1 and position 2']
        random.shuffle(choices)
        return choices

    def information_channel_4_choices(self):
        choices = ['Draw a ball from the actual urn selected for your 4-member group in this round',
                   'See the respective group urn guesses by players in position 1, position 2, and position 3']
        random.shuffle(choices)
        return choices

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields

    def outcome3_P1_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def outcome3_P2_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def outcome4_P1_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    def outcome4_P2_choices(self):
        choices = ['Red urn', 'Blue urn']
        random.shuffle(choices)
        return choices

    information_channel_2 = models.StringField(
        choices=[
            'Draw a ball from the actual urn selected for your 4-member group in this round',
            'See the group urn guess by the player in position 1'],
        widget=widgets.RadioSelect
    )

    information_channel_3 = models.StringField(
        choices=[
            'Draw a ball from the actual urn selected for your 4-member group in this round',
            'See the respective group urn guesses by players in position 1 and position 2'],
        widget=widgets.RadioSelect
    )

    information_channel_4 = models.StringField(
        choices=[
            'Draw a ball from the actual urn selected for your 4-member group in this round',
            'See the respective group urn guesses by players in position 1, position 2, and position 3'],
        widget=widgets.RadioSelect
    )

    urn_choice_red_2 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is red:'
    )

    urn_choice_blue_2 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is blue:'
    )

    urn_choice_red_3 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is red:'
    )

    urn_choice_blue_3 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is blue:'
    )

    urn_choice_red_4 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is red:'
    )

    urn_choice_blue_4 = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is blue:'
    )

    urn_choice_position1_red = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is red:'
    )

    urn_choice_position1_blue = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...one ball has been randomly drawn from the actual group urn and it is blue:'
    )

    social_info_2_R = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...the player in position 1 has guessed the Red urn?'
    )

    social_info_2_B = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...the player in position 1 has guessed the Blue urn?'
    )

    social_info_3_RR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1 and position 2 have respectively guessed Red urn; and Red urn?'
    )

    social_info_3_RB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1 and position 2 have respectively guessed Red urn; and Blue urn?'
    )

    social_info_3_BR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1 and position 2 have respectively guessed Blue urn; and Red urn?'
    )

    social_info_3_BB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1 and position 2 have respectively guessed Blue urn; and Blue urn?'
    )

    social_info_4_RRR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Red urn; Red urn,'
              ' and Red urn?'
    )

    social_info_4_RRB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Red urn; Red urn,'
              ' and Blue urn?'
    )

    social_info_4_RBR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Red urn; Blue urn,'
              ' and Red urn?'
    )

    social_info_4_BRR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Blue urn; Red urn,'
              ' and Red urn?'
    )

    social_info_4_BBB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Blue urn; Blue urn,'
              ' and Blue urn?'
    )

    social_info_4_BBR = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Blue urn; Blue urn,'
              ' and Red urn?'
    )

    social_info_4_BRB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Blue urn; Red urn,'
              ' and Blue urn?'
    )

    social_info_4_RBB = models.StringField(
        choices=[
            'Red urn', 'Blue urn'],
        widget=widgets.RadioSelect,
        label='...players in position 1, position 2, and position 3 have respectively guessed Red urn; Blue urn,'
              ' and Blue urn?'
    )

    true_false_1 = models.StringField(
        choices=[
            'True', 'False'],
        widget=widgets.RadioSelect,
        label='The actual group urn selected in each round is equally likely to be “Red” or “Blue”.'
              ' (+$0.10 to your bonus if correct)'
    )

    true_false_2 = models.StringField(
        choices=[
            'True', 'False'],
        widget=widgets.RadioSelect,
        label='The other 3 participants in your group face the same problem as you: guessing the selected group'
              ' urn in every round. (+$0.10 to your bonus if correct)'
    )

    true_false_3 = models.StringField(
        choices=[
            'True', 'False'],
        widget=widgets.RadioSelect,
        label='For a given round, the randomly selected group urn is the same for all members of your 4-member group.'
              ' (+$0.10 to your bonus if correct)'
    )

    true_false_7 = models.StringField(
        choices=[
            'True', 'False'],
        widget=widgets.RadioSelect,
        label='The “Red” urn always contains two red balls and one blue ball. The “Blue” urn always contains two '
              'blue balls and one red ball. (+$0.10 to your bonus if correct)'
    )

    outcome3_P1 = models.StringField(
        choices=['Red urn', 'Blue urn'],
        label=''
    )

    outcome3_P2 = models.StringField(
        choices=['Red urn', 'Blue urn'],
        label=''
    )

    outcome4_P1 = models.StringField(
        choices=['Red urn', 'Blue urn'],
        label=''
    )

    outcome4_P2 = models.StringField(
        choices=['Red urn', 'Blue urn'],
        label=''
    )
