using System;
using UnityEngine;
using System.Collections.Generic;
namespace Mirror
{
    /// 
    /// Component that limits visibility of networked objects to the authority client.
    /// Any object with this component on it will only be visible to the client that has been assigned authority for it.
    /// This would be used for spawning a non-player networked object for single client to interact with, e.g. in-game puzzles.
    /// 
    // Deprecated 2021-09-06
    [Obsolete(NetworkVisibilityObsoleteMessage.Message)]
    [DisallowMultipleComponent]
    [AddComponentMenu("Network/NetworkOwnerChecker")]
    [RequireComponent(typeof(NetworkIdentity))]
    [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-owner-checker")]
    public class NetworkOwnerChecker : NetworkVisibility
    {
        /// 
        /// Callback used by the visibility system to determine if an observer (player) can see this object.
        /// If this function returns true, the network connection will be added as an observer.
        /// 
        /// Network connection of a player.
        /// True if the client is the owner of this object.
        public override bool OnCheckObserver(NetworkConnection conn)
        {
            // Debug.Log($"OnCheckObserver {netIdentity.connectionToClient} {conn}");
            return (netIdentity.connectionToClient == conn);
        }
        /// 
        /// Callback used by the visibility system to (re)construct the set of observers that can see this object.
        /// 
        /// The new set of observers for this object.
        /// True if the set of observers is being built for the first time.
        public override void OnRebuildObservers(HashSet observers, bool initialize)
        {
            // Do nothing here because the authority client is always added as an observer internally.
        }
    }
}