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

namespace Service.Implement
{
    public class RoomTypeModalManager : GenericManagerBase<RoomTypeModal>, IRoomTypeModalManager
    {
        public IList<RoomTypeModal> LoadAllByPage(out long total, int page, int rows, string order, string sort, int roomTypeId)
        {
            return ((Dao.IRoomTypeModalRepository)(this.CurrentRepository)).LoadAllByPage(out total, page, rows, order, sort, roomTypeId).ToList();
        }

        public IList<RoomTypeModal> LoadAll(int? roomTypeId, int sourceType = -1)
        {
            if (sourceType == -1)
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType != null && r.RoomType.ID == roomTypeId).ToList();
            }
            else
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType != null && r.RoomType.ID == roomTypeId && r.SourceType == sourceType).ToList();
            }
        }

        public IList<RoomTypeModal> LoadAll(RoomType roomType, int sourceType)
        {
            if (sourceType == -1)
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType == roomType).ToList();
            }
            else
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType == roomType && r.SourceType == sourceType).ToList();
            }
        }

        public IList<RoomTypeModal> LoadAll(RoomType roomType, DeviceType deviceType, int sourceType)
        {
            if (sourceType == -1)
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType == roomType && r.Type == deviceType).ToList();
            }
            else
            {
                return CurrentRepository.LoadAll().Where(r => r.RoomType == roomType && r.Type == deviceType && r.SourceType == sourceType).ToList();
            }
        }

        public void Delete(RoomTypeModal roomTypeModal)
        {
            this.Delete(roomTypeModal.ID);
        }

        public void DeleteByRoomTypeID(int roomTypeID, int sourceType)
        {
            ((Dao.IRoomTypeModalRepository)(this.CurrentRepository)).DeleteByRoomTypeID(roomTypeID, sourceType);
        }


        public void DeleteByAddress(int roomTypeID, string address)
        {
            ((Dao.IRoomTypeModalRepository)(this.CurrentRepository)).DeleteByAddress(roomTypeID, address);
        }
    }
}
