package com.elgassia.bridge.adapter.main;

import com.elgassia.bridge.Model.TeamModel;
import com.elgassia.bridge.Model.UserTeamModel;
import com.elgassia.bridge.adapter.LobbyAdapter;

public class TeamAdapter implements com.elgassia.bridge.adapter.TeamAdapter {
    private MainAdapter main_adapter;
    private TeamModel team_model;
    private com.elgassia.bridge.adapter.LobbyAdapter lobby_adapter;

    int[] players;
    int active_player;
    UserTeamModel[] player_team_models;

    @Override
    public void init(MainAdapter main_adapter, TeamModel team_model) {
        this.main_adapter = main_adapter;
        this.team_model = team_model;

        lobby_adapter = new com.elgassia.bridge.adapter.main.LobbyAdapter();
        lobby_adapter.init(this);

        assert team_model != null;

        players = team_model.getPlayerOrder();
        active_player = 0;
        player_team_models = new UserTeamModel[players.length];
        for (int i = 0; i < players.length; ++i) {
            player_team_models[i] = new UserTeamModel(players[i], team_model);
        }
    }

    @Override
    public void nextPlayer() {
        active_player = (active_player + 1) % players.length;
    }

    @Override
    public UserTeamModel getUserTeamModel() {
        return player_team_models[active_player];
    }

    @Override
    public String getName() {
        return getUserTeamModel().getPlayerName();
    }

    @Override
    public LobbyAdapter getLobbyAdapter() {
        return lobby_adapter;
    }

    @Override
    public UserTeamModel[] getUserTeamModels() {
        return player_team_models;
    }
}

@@ -178,16 +178,73 @@
 apter;%0A%0A
+import java.util.Observable;%0Aimport java.util.Observer;%0A%0A
 public c
@@ -310,18 +310,105 @@
 mAdapter
- %7B
+, Observer %7B%0A    public enum State %7B%0A        LOBBY,%0A        BIDDING,%0A        GAME,%0A    %7D%0A
 %0A    pri
@@ -579,24 +579,24 @@
 ive_player;%0A
-
     UserTeam
@@ -624,16 +624,117 @@
 odels;%0A%0A
+    private State state;%0A%0A    public void setState(State state) %7B%0A        this.state = state;%0A    %7D%0A%0A
     @Ove
@@ -1855,11 +1855,488 @@
 s;%0A    %7D
+%0A%0A    @Override%0A    public void update(Observable observable, Object o) %7B%0A        if (observable == team_model) %7B%0A            switch (team_model.getState()) %7B%0A                case 'L':%0A                    setState(State.LOBBY);%0A                    break;%0A                case 'B':%0A                    setState(State.BIDDING);%0A                    break;%0A                case 'G':%0A                    setState(State.GAME);%0A                    break;%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

add TeamAdapter.State