﻿using System;

namespace Desalination
{
    public class SimulatedFighter
    {
        public SimulatedFighter(SaltyFighter fighter)
        {
            Name = fighter.Name;
            Wins = fighter.Wins;
            Loses = fighter.Loses;
        }

        // Copied from SaltyFighter.
        public int ID { get; set; }
        public string Name { get; set; }
        public int Wins { get; set; }
        public int Loses { get; set; }

        // Extended properties.
        public SaltyHandicaps Handicaps { get; set; }
        public double HandicapPercentage { get; set; }
        public double Experience { get; set; }
        public double Stupidity { get; set; }

        public static bool IsWithin(double value, double minimum, double maximum)
        {
            return value >= minimum && value <= maximum;
        }

        public int GetTotalMatches()
        {
            return (Wins + Loses);
        }

        public int GetNormalizedPercentages()
        {
            var handicap = (int) GetHandicapedPercentage();
            if (IsWithin(handicap, 0, 9))
            {
                return 00;
            }
            if (IsWithin(handicap, 10, 19))
            {
                return 11;
            }
            if (IsWithin(handicap, 20, 29))
            {
                return 22;
            }
            if (IsWithin(handicap, 30, 39))
            {
                return 33;
            }
            if (IsWithin(handicap, 40, 49))
            {
                return 44;
            }
            if (IsWithin(handicap, 50, 59))
            {
                return 55;
            }
            if (IsWithin(handicap, 60, 69))
            {
                return 66;
            }
            if (IsWithin(handicap, 70, 79))
            {
                return 77;
            }
            if (IsWithin(handicap, 80, 89))
            {
                return 88;
            }
            if (IsWithin(handicap, 90, 100))
            {
                return 99;
            }
            return handicap > 100 ? 111 : handicap;
        }

        public double GetHandicapedPercentage()
        {
            // Returns modified percentage with all known information about fighter included.
            return Math.Round(((GetBasePercentage() + HandicapPercentage + Experience) - Stupidity), 2);
        }

        public double GetBasePercentage()
        {
            // Return base amount without any handicaps or minuses.
            return Math.Round(((double) Wins/GetTotalMatches()), 2);
        }
    }
}