using System;
using UnityEngine;

namespace pdinklag
{
    /// <summary>
    /// Declares a content type for asset bundles.
    /// </summary>
    public struct ContentType
    {
        public static readonly ContentType AnimationClip = new(typeof(AnimationClip), "anims", "anims", "Anim");
        public static readonly ContentType AudioClip = new(typeof(AudioClip), "audio/clips", "audioClips");
        public static readonly ContentType AudioClipGroup = new(typeof(AudioClipGroup), "audio/groups", "audioClipGroups", "SoundGroup");
        public static readonly ContentType Localization = new(typeof(LocalizationAsset), "localization", "localizationAssets");
        public static readonly ContentType Material = new(typeof(Material), "materials", "materials");
        public static readonly ContentType Mesh = new(typeof(Mesh), "meshes", "meshes");
        public static readonly ContentType Prefab = new(typeof(GameObject), "prefabs", "prefabs");
        public static readonly ContentType Texture = new(typeof(Texture2D), "textures", "textures");

        public static readonly AssetAddress SceneAddressPrefix = "scenes";

        /// <summary>
        /// The declared asset type.
        /// </summary>
        public Type AssetType;

        /// <summary>
        /// The prefix for addresses of assets of this type.
        /// </summary>
        public readonly AssetAddress AddressPrefix;

        /// <summary>
        /// The label for assets of this type.
        /// </summary>
        public readonly AssetLabel Label;

        /// <summary>
        /// The class name for automatically generated content scripts.
        /// </summary>
        public readonly string ClassName;

        public ContentType(Type assetType, AssetAddress addressPrefix, AssetLabel label, string contentClassName)
        {
            AssetType = assetType;
            AddressPrefix = addressPrefix;
            Label = label;
            ClassName = contentClassName;
        }

        public ContentType(Type assetType, AssetAddress addressPrefix, AssetLabel label) : this(assetType, addressPrefix, label, string.Empty)
        {
        }

        public ContentType(Type assetType, AssetAddress addressPrefix) : this(assetType, addressPrefix, AssetLabel.None, string.Empty)
        {
        }

        public AssetAddress CompileAddress(AssetAddress prefix, string name) 
            => prefix.Combine(AddressPrefix).Combine(name);
    }
}
