using System;
using System.Collections.Generic;
using TABS.MailCarrier.WebSDK.Board;

/// <summary>
/// BoardSubscribedDataSource의 요약 설명입니다.
/// </summary>
public class BoardSubscribedDataSource
{
    public class BoardItem
    {
        public Guid ID { get; set; }
        public string Name { get; set; }
        public bool Subscribed { get; set; }
    }

    public BoardSubscribedDataSource()
    {        
    }

    public List<BoardItem> GetBoards()
    {
        string userEmail = WebUser.CurrentUser.MailAddress;
        List<BoardItem> boardList = new List<BoardItem>();
        UserBoard userBoard = new UserBoard(WebUser.CurrentUser.DomainUserID);
        Board[] subscribeBoards = userBoard.SubscribedBoards;

        Board[] shareBoards = userBoard.ShareBoards;
        foreach (Board shareBoard in shareBoards)
        {
            if (shareBoard.Type == Board.BoardType.General && AppSetting.PassDisplayBoardFilter(shareBoard.ID, userEmail))
            {
                bool subscribed = false;
                foreach (Board subBoard in subscribeBoards)
                {
                    if (shareBoard.ID == subBoard.ID)
                    {
                        subscribed = true;
                        break;
                    }
                }
                BoardItem item = new BoardItem();
                item.ID = shareBoard.ID;
                item.Name = shareBoard.Name;
                item.Subscribed = subscribed;
                boardList.Add(item);
            }
        }
        return boardList;
    }
}