/* Copyright © 2014 Apex Software. All rights reserved. */
namespace Apex.AI.Editor
{
    using System.IO;
    using Apex.Editor;
    using UnityEditor;
    using UnityEngine;

    public static class ContextGenerator
    {
        public static void WriteContextFiles(string nameSpace)
        {
            if (string.IsNullOrEmpty(nameSpace))
            {
                nameSpace = "MyNamespace";
            }

            var filePath = AssetPath.Combine(Application.dataPath, "BasicContext.cs");
            using (var writer = new StreamWriter(filePath))
            {
                writer.Write(Template.ContextTemplate, nameSpace);
            }

            filePath = AssetPath.Combine(Application.dataPath, "BasicContextProvider.cs");
            using (var writer = new StreamWriter(filePath))
            {
                writer.Write(Template.ProviderTemplate, nameSpace);
            }

            AssetDatabase.Refresh();
        }

        private class Template
        {
            public const string ProviderTemplate = @"//------------------------------------------------------------------------------
// <auto-generated>
// This class was auto generated by the Context Generator
// </auto-generated>
//------------------------------------------------------------------------------
namespace {0}
{{
    using System;
    using Apex.AI;
    using Apex.AI.Components;
    using UnityEngine;

    public class BasicContextProvider : MonoBehaviour, IContextProvider
    {{
        private IAIContext _context;

        private void Awake()
        {{
            _context = new BasicContext();
        }}

        public IAIContext GetContext(Guid aiId)
        {{
            return _context;
        }}
    }}
}}";

            public const string ContextTemplate = @"//------------------------------------------------------------------------------
// <auto-generated>
// This class was auto generated by the Context Generator
// </auto-generated>
//------------------------------------------------------------------------------
namespace {0}
{{
    using Apex.AI;

    public class BasicContext : IAIContext
    {{
    }}
}}";
        }
    }
}
