using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain;

namespace Service.Implement
{
	public class SearchHostManager : ISearchHostManager
	{
        public RCUHost.IHostSearchReceiver HostSearchReceiver { get; set; }        
        
        public Dao.IHostRepository HostRepository { get; set; }

		public void Start(SearchHostResultHandler handler)
		{
			HostSearchReceiver.Start(handler);
		}

		public void Start()
		{
			HostSearchReceiver.Start();
		}

		public string User
		{
			get
			{
				return HostSearchReceiver.User;
			}
			set
			{
				HostSearchReceiver.User = value;
			}
		}

		public bool Searching
		{
			get { return HostSearchReceiver.Searching; }
		}

		public void Stop()
		{
			HostSearchReceiver.Stop();
		}

        public bool UpdateHost(SearchHost host, int hotelID)
        {
            var hostRepository = HostRepository.GetByMAC(host.MAC, hotelID);
            if (hostRepository != null)
            {
                hostRepository.SubnetMask = host.SubnetMask;
                hostRepository.Gateway = host.Gateway;
                hostRepository.Port = host.Port;
                hostRepository.Version = host.Version;
                hostRepository.ConfigVersion = host.ConfigVersion;

                HostRepository.Update(hostRepository);

                return true;
            }
            return false;
        }
	}
}
