﻿using UnityEditor;
using UnityEngine;

namespace LicenseSpring
{
    [CustomEditor(typeof(LicenseSpringSDKObject))]
    public class LicenseSpringObjectEditor : Editor
    {
        private SerializedProperty apiKey;
        private SerializedProperty sharedKey;
        private SerializedProperty productCode;
        private SerializedProperty useCustomProductData;
        private SerializedProperty appName;
        private SerializedProperty appVersion;

        private void OnEnable()
        {
            apiKey = serializedObject.FindProperty("apiKey");
            sharedKey = serializedObject.FindProperty("sharedKey");
            productCode = serializedObject.FindProperty("productCode");
            useCustomProductData = serializedObject.FindProperty("UseCustomProductData");
            appName = serializedObject.FindProperty("appName");
            appVersion = serializedObject.FindProperty("appVersion");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(apiKey, new GUIContent("Api key: "));
            EditorGUI.indentLevel--;

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(sharedKey, new GUIContent("Shared key: "));
            EditorGUI.indentLevel--;

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(productCode, new GUIContent("Product code: "));
            EditorGUI.indentLevel--;
            

            EditorGUILayout.PropertyField(useCustomProductData, new GUIContent("Use custom product data"));

            if (useCustomProductData.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(appName, new GUIContent("Application name: "));
                EditorGUI.indentLevel--;

                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(appVersion, new GUIContent("Application version: "));
                EditorGUI.indentLevel--;
            }


            EditorGUILayout.Space();
            
            serializedObject.ApplyModifiedProperties();
        }
    }
}
