from otree.api import *

doc = """
Your app description
"""


class C(BaseConstants):
    NAME_IN_URL = 'Analysing_Political_Corruption'
    PLAYERS_PER_GROUP = 7
    NUM_ROUNDS = 1
    PoliticianA_Role = 'Politician_A'
    PoliticianB_Role = 'Politician_B'
    Voter1_Role = 'Voter_1'
    Voter2_Role = 'Voter_2'
    Voter3_Role = 'Voter_3'
    Voter4_Role = 'Voter_4'
    Voter5_Role = 'Voter_5'


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    vote_share = models.FloatField()


class Player(BasePlayer):
    pga = models.IntegerField(min=1, max=100, label="Public Good Provision: 公共品：")
    pgb = models.IntegerField(min=1, max=100, label="Public Good Provision: 公共品：")
    taxa = models.IntegerField(min=1, max=100, label="Tax Amount: 税收：")
    taxb = models.IntegerField(min=1, max=100, label="Tax Amount: 税收：")

    vote1 = models.IntegerField(
        choices=[
            [1, 'A'],
            [0, 'B']
        ], label="Vote for A or B"
    )

    vote2 = models.IntegerField(
        choices=[
            [1, 'A'],
            [0, 'B']
        ], label="Vote for A or B"
    )

    vote3 = models.IntegerField(
        choices=[
            [1, 'A'],
            [0, 'B']
        ], label="Vote for A or B"
    )

    vote4 = models.IntegerField(
        choices=[
            [1, 'A'],
            [0, 'B']
        ], label="Vote for A or B"
    )

    vote5 = models.IntegerField(
        choices=[
            [1, 'A'],
            [0, 'B']
        ], label="Vote for A or B"
    )


#def pga_max(player):
#    return player.taxa


#def pgb_max(player):
#    return player.taxb


#def pga_error_message(player, value):
#    print('Public good level is', value)
#    if value > player.taxa:
#        return 'Cannot offer public good more than your tax budget. 不能提供比税收更高的公共品。'



# PAGES
class PoliticianProposalA(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.PoliticianA_Role

    form_model = 'player'
    form_fields = ['taxa', 'pga']




class PoliticianProposalB(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.PoliticianB_Role

    form_model = 'player'
    form_fields = ['taxb', 'pgb']


class ResultsWaitPage(WaitPage):
    pass


class VotingStage1(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.Voter1_Role

    form_model = 'player'
    form_fields = ['vote1']


class VotingStage2(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.Voter2_Role

    form_model = 'player'
    form_fields = ['vote2']


class VotingStage3(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.Voter3_Role

    form_model = 'player'
    form_fields = ['vote3']


class VotingStage4(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.Voter4_Role

    form_model = 'player'
    form_fields = ['vote4']


class VotingStage5(Page):
    @staticmethod
    def is_displayed(player):
        return player.role == C.Voter5_Role

    form_model = 'player'
    form_fields = ['vote5']


page_sequence = [PoliticianProposalA, PoliticianProposalB, ResultsWaitPage, VotingStage1, VotingStage2, VotingStage3,
                 VotingStage4, VotingStage5]
