using Framework.StatSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Testing.Root;
using UnityEngine;

namespace Testing.StatSystem
{
    // TODO Comment
    public class StatTests : Tests
    {
        Stat stat;

        public void Setup()
        {
            this.stat = new Stat(1f);
        }

        public void Shutdown()
        {
            this.stat = null;
        }

        public void SetSuperstatTest()
        {
            Stat superstat = new Stat(1f);
            superstat.AddModifier(new ScaleModifier(2f));
            this.stat.SetSuperstat(superstat); 
            Assert(this.stat.GetModifiers().Count, 1, "Modifier count = 1");
            Assert(this.stat.GetValue(), 2f, "Value = 2");
        }

        public void SetSuperstatTest_SuperSuper()
        {
            Stat supersuperstat = new Stat(1f);
            supersuperstat.AddModifier(new ScaleModifier(2f));

            Stat superstat = new Stat(1f);
            superstat.AddModifier(new ShiftModifier(1f)); 
            superstat.SetSuperstat(supersuperstat);

            stat.SetSuperstat(superstat);
            Assert(this.stat.GetModifiers().Count, 2, "Modifier count = 2");
            Assert(this.stat.GetValue(), 3f, "Value = 3");
        }

        public void AddModifierTest()
        {
            this.stat.AddModifier(new ShiftModifier(1f));
            Assert(this.stat.GetValue(), 2f, "Value = 2");
            Assert(this.stat.GetModifiers().Count, 1, "Modifier count = 1");
        }

        public void RemoveModifierTest()
        {
            ShiftModifier modifier = new ShiftModifier(1f);

            this.stat.AddModifier(modifier);
            Assert(this.stat.GetModifiers().Count, 1, "Modifier count = 1");

            this.stat.RemoveModifier(modifier);
            Assert(this.stat.GetValue(), 1f, "Value = 1");
            Assert(this.stat.GetModifiers().Count, 0, "Modifier count = 0");
        }

        public void RemoveModifierTest_TypeAndStrength()
        {
            ShiftModifier shift = new ShiftModifier(1f);
            ScaleModifier scale = new ScaleModifier(1f);

            this.stat.AddModifier(shift);
            this.stat.AddModifier(scale);
            Assert(this.stat.GetModifiers().Count, 2, "Modifier count = 2");

            this.stat.RemoveModifier<ShiftModifier>(1f);
            Assert(this.stat.GetValue(), 1f, "Value = 1");
            Assert(this.stat.GetModifiers().Count, 1, "Modifier count = 1");
        }

        public void GetValueTest_ShiftScale()
        {
            ShiftModifier shift = new ShiftModifier(1f);
            ScaleModifier scale = new ScaleModifier(3f);

            this.stat.AddModifier(shift);
            this.stat.AddModifier(scale);
            Assert(this.stat.GetValue(), 4f, "Value = 4");
        }

        public void GetValueTest_ScaleScale()
        {
            ScaleModifier scale1 = new ScaleModifier(1.5f);
            ScaleModifier scale2 = new ScaleModifier(3f);

            this.stat.AddModifier(scale1);
            this.stat.AddModifier(scale2);
            Assert(this.stat.GetValue(), 3.5f, "Value = 3.5");
        }

        public void GetValueTest_ShiftShift()
        {
            ShiftModifier shift1 = new ShiftModifier(1f);
            ShiftModifier shift2 = new ShiftModifier(-1f);

            this.stat.AddModifier(shift1);
            this.stat.AddModifier(shift2);
            Assert(this.stat.GetValue(), 1f, "Value = 1");
        }

        private void Log(string message)
        {
            Debug.Log(message);
        }
    }
}
