from otree.api import *


doc = """
Your app description
"""


class C(BaseConstants):
    NAME_IN_URL = 'my_public_goods'
    PLAYERS_PER_GROUP = 3
    NUM_ROUNDS = 1
    endowment = cu(1000)
    multiplier = 2


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    total_contribution = models.CurrencyField
    individual_share = models.CurrencyField


def set_payoffs(self):
        players = self.get_players()
        contributions = [p.contribution for p in players]
        total_contribution = sum(contributions)
        individual_share = total_contribution * C.multiplier / C.PLAYERS_PER_GROUP
        for player in players:
            player.payoff = C.endowment - player.contribution + self.individual_share

print(Group.total_contribution)

class Player(BasePlayer):
    contribution = models.CurrencyField(
        min=0,
        max=C.endowment,
        label="How much will you contribute?"
    )


# PAGES
class Contribute(Page):
    form_model = 'player'
    form_fields = ['contribution']


class ResultsWaitPage(WaitPage):
    after_all_players_arrive = 'set_payoffs'


class Results(Page):
    pass

page_sequence = [Contribute, ResultsWaitPage, Results]
