using System;
using UnityEngine;

namespace pdinklag
{
    [CreateAssetMenu(fileName = "MyBundle", menuName = "Asset Bundle Info")]
    public class AssetBundleInfo : ScriptableObject
    {
        public static readonly int CURRENT_DATA_VERSION = 1;

        public static readonly AssetLabel InfoLabel = "info";

        public static readonly string ScriptsAssetLabel = "scripts";

        [Header("General Information")]
        [Tooltip("The name of the bundle as displayed to the user.")]
        public string DisplayName = "My Bundle";

        [Tooltip("A short text describing the contents of the bundle. This may also be a localization key.")]
        [TextArea]
        public string Description = "";

        [Tooltip("The author of the bundle.")]
        public string Author = "Anonymous";

        [Header("Addressable Settings")]
        [Tooltip("The prefix for asset addresses in this bundle.")]
        public string AddressPrefix = "";

        [Tooltip("The prefix for asset addresses in this bundle.")]
        public string ScriptsAssetName = "scripts";

        [HideInInspector]
        [Tooltip("The globally unique identifier for the bundle. This is assigned during the first build of the bundle and should never be changed manually.")]
        public string Guid = System.Guid.Empty.ToString();

        [HideInInspector]
        [Tooltip("The build number of the bundle. This is incremented each time the bundle is built, but serves only informational purposes.")]
        public int BuildNumber = 0;

        [HideInInspector]
        [Tooltip("The data version of the bundle. The game may opt not to load a bundle if its data version is too old. Managed automatically.")]
        public int DataVersion = 0;

        [HideInInspector]
        [Tooltip("If set, no bundle file will be generated and this bundle will always be loaded no matter the user preferences.")]
        public bool BuiltIn;

        [HideInInspector]
        public string AssemblyName = "";

        [HideInInspector]
        public string LastGroupName = "";

        [HideInInspector]
        [NonSerialized]
        public string CatalogPath = "";

        /// <summary>
        /// Creates an address relative to this bundle's address prefix.
        /// </summary>
        /// <param name="relativeAddress">the relative address</param>
        /// <returns></returns>
        public AssetAddress Address(AssetAddress relativeAddress) => new AssetAddress(AddressPrefix).Combine(relativeAddress);

        private void Reset()
        {
            Author = Environment.UserName;
        }
    }
}
