using Framework.GuardianSaveSystem;
using Framework.Utility;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Testing.Root;
using UnityEngine;

namespace Testing.GuardianSaveSystem
{
    public class MomentTests : Tests
    {
        private int index;
        private Moment moment;
        private GameObject go1;
        private GameObject go2;
        private GameObject go3;
        private int saveLoadFileIndex1;

        public MomentTests()
        {
        }

        private int GetIndex()
        {
            return index++;
        }

        public void Setup()
        {
        }

        public void Shutdown()
        {
        }

        public void ConstructorTest()
        {
            string name = "ConstructorTest";
            moment = new Moment(name);
            Assert(moment != null, "Moment is not null.");
            Assert(File.Exists(UnityFile.GetPath() + name + @"/" + name + ".txt"), "File exists.");
            Directory.Delete(UnityFile.GetPath() + name, true);
        }

        public void ConstructorTest_Overlap()
        {
            string name = "ConstructorTest";
            moment = new Moment(name);
            Assert(moment != null, "Moment is not null.");
            Assert(File.Exists(UnityFile.GetPath() + name + @"/" + name + ".txt"), "File exists.");
            Directory.Delete(UnityFile.GetPath() + name, true);
        }

        public void ConstructorTest_InvalidName()
        {
            //string name = DateTime.Now.ToString(@"/!.!///");
            //moment = new Moment(name);
            //Assert(moment != null, "Moment is not null.");
            //Assert(File.Exists(UnityFile.GetPath() + name + @"/" + name + ".txt"), "File exists.");
        }

        public void SaveScene_Test()
        {
            go1 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());
            go2 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());
            go3 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());

            this.moment = new Moment("SaveSceneTest");
            this.moment.SaveScene();
            Assert(this.moment.HasScene(Application.loadedLevelName), "Has scene.");

            GameObject.DestroyImmediate(go1);
            GameObject.DestroyImmediate(go2);
            GameObject.DestroyImmediate(go3);
            Directory.Delete(UnityFile.GetPath() + "SaveSceneTest", true);
        }

        public void LoadScene_Test()
        {
            go1 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());
            go2 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());
            go3 = (GameObject)GameObject.Instantiate(Resources.Load("Cube"), Vector3.zero, new Quaternion());

            this.moment = new Moment("LoadSceneTest");
            this.moment.SaveScene();
            Assert(this.moment.HasScene(Application.loadedLevelName), "Has scene.");

            GameObject.DestroyImmediate(go1);
            GameObject.DestroyImmediate(go2);
            GameObject.DestroyImmediate(go3);

            //Assert(GameObject.FindGameObjectsWithTag("Test").Length == 3, "GameObjects exist. Found: " + GameObject.FindGameObjectsWithTag("Test").Length + ", expected 3.");
            this.moment = new Moment("LoadSceneTest");
            this.moment.LoadScene();
            Assert(GameObject.FindGameObjectsWithTag("Test").Length == 3, "GameObjects exist. Found: " + GameObject.FindGameObjectsWithTag("Test").Length + ", expected 3.");
            Directory.Delete(UnityFile.GetPath() + "LoadSceneTest", true);
        }
    }
}
