using FishNet.Connection;
using FishNet.Object;
using UnityEngine;
namespace FishNet.Component.Ownership
{
    /// 
    /// Adding this component allows any client to use predictive spawning on this prefab.
    /// 
    public class PredictedSpawn : NetworkBehaviour
    {
        #region Serialized.
        /// 
        /// True to allow clients to predicted spawn this object.
        /// 
        public bool GetAllowSpawning() => _allowSpawning;
        /// 
        /// Sets to allow predicted spawning. This must be set on client and server.
        /// 
        /// New value.
        public void SetAllowSpawning(bool value) => _allowSpawning = value;
        [Tooltip("True to allow clients to predicted spawn this object.")]
        [SerializeField]
        private bool _allowSpawning = true;
        /// 
        /// True to allow clients to predicted despawn this object.
        /// 
        public bool GetAllowDespawning() => _allowDespawning;
        /// 
        /// Sets to allow predicted despawning. This must be set on client and server.
        /// 
        /// New value.
        public void SetAllowDespawning(bool value) => _allowDespawning = value;
        [Tooltip("True to allow clients to predicted despawn this object.")]
        [SerializeField]
        private bool _allowDespawning = true;
        /// 
        /// 
        /// 
        [Tooltip("True to allow clients to predicted set syncTypes prior to spawning the item. Set values will be applied on the server and sent to other clients.")]
        [SerializeField]
        private bool _allowSyncTypes = true;
        /// 
        /// True to allow clients to predicted set syncTypes prior to spawning the item. Set values will be applied on the server and sent to other clients.
        /// 
        public bool GetAllowSyncTypes() => _allowSyncTypes;
        /// 
        /// Sets to allow syncTypes. This must be set on client and server.
        /// 
        /// New value.
        public void SetAllowSyncTypes(bool value) => _allowSyncTypes = value;
        #endregion
        /// 
        /// Called on the client when trying to predicted spawn this object.
        /// 
        /// Owner specified to spawn with.
        /// True if able to spawn.
        public virtual bool OnTrySpawnClient(NetworkConnection owner = null)
        {
            return GetAllowSpawning();
        }
        /// 
        /// Called on the server when a client tries to predicted spawn this object.
        /// 
        /// Connection trying to predicted spawn this object.
        /// Owner specified to spawn with.
        /// True if able to spawn.
        public virtual bool OnTrySpawnServer(NetworkConnection spawner, NetworkConnection owner = null)
        {
            return GetAllowSpawning();
        }
        /// 
        /// Called on the client when trying to predicted spawn this object.
        /// 
        /// True if able to despawn.
        public virtual bool OnTryDespawnClient()
        {
            return GetAllowDespawning();
        }
        /// 
        /// Called on the server when a client tries to predicted despawn this object.
        /// 
        /// Connection trying to predicted despawn this object.
        /// True if able to despawn.
        public virtual bool OnTryDepawnServer(NetworkConnection despawner)
        {
            return GetAllowDespawning();
        }
    }
}