package objects.bets;

import objects.SoccerMatch;

public class AsianHandicap extends Bet {

    float handicap;

    public AsianHandicap(SoccerMatch match, String bet, float betAmount, float betOdds, float handicap) {
        super(0, match, bet, betAmount, betOdds);
        this.handicap = handicap;
    }

    public float getHandicap() {
        return handicap;
    }

    public void setHandicap(float handicap) {
        this.handicap = handicap;
    }

    @Override
    public float getResult() {
        float result = super.getResult();
        int adjustment = (int) Math.floor(handicap);
        int homeScore = match.getHomeScore();
        if (adjustment > 0) {
            homeScore += adjustment;
        } else {
            homeScore -= adjustment;
        }

        if (handicap == 0f) {
            if (!correctBet() && isDrawResult()) {
                result = betAmount;
            }
        } else if (handicap == -0.25f) {
            if (!correctBet() && isDrawResult()) {
                result = betAmount / 2;
            }
        } else if (handicap == 0.25f) {
            if (!correctBet() && isDrawResult()) {
                result = (betAmount / 2) + (betAmount * betOdds) / 2;
            }
        } else if (handicap == -0.5f) {
            result = super.getResult();
        } else if (handicap == 0.5f) {
            if (!correctBet() && isDrawResult()) {
                result = super.getResult();
            }
        } else if (handicap == -0.75f) {
            if (homeScore - 2 > match.getAwayScore()) {
                result = super.getResult();
            } else if (homeScore - 1 > match.getAwayScore()) {
                result = (betAmount / 2) + (betAmount * betOdds) / 2;
            }
        } else if (handicap == 0.75f) {
            if (!correctBet() && isDrawResult()) {
                result = super.getResult();
            } else {
                if (homeScore - 1 >= match.getAwayScore()) {
                    result = betAmount / 2;
                }
            }
        }

        return result;
    }

}
