using System;
using System.Collections.Generic;
using System.Web;
using TABS.MailCarrier.WebSDK.Approval;

/// <summary>
/// 결재함 폴더 구조를 반환하는 데이터 소스 클래스입니다.
/// </summary>
public class AppFolderDataSource
{
    public class FolderItem
    {
        private Guid _parentId;
        private Guid _id;
        private string _folderName;
        private int _newCount;
        private int _totalCount;
        private int _indent;
        private string _iconName;

        public FolderItem(Guid parentId, Guid id, string folderName, int newCount, int totalCount, int indent, string iconName)
        {
            _parentId = parentId;
            _id = id;
            _folderName = folderName;
            _newCount = newCount;
            _totalCount = totalCount;
            _indent = indent;
            _iconName = iconName;
        }

        public Guid ParentID
        {
            get { return _parentId; }
        }

        public Guid ID
        {
            get { return _id; }
        }

        public string FolderName
        {
            get { return _folderName; }
        }

        public int NewCount
        {
            get { return _newCount; }
        }

        public int TotalCount
        {
            get { return _totalCount; }
        }

        public int Indent
        {
            get { return _indent; }
        }

        public string IconName
        {
            get { return _iconName; }
        }
    }

    public static Guid DRAFT_FOLDERID = new Guid("916501ec-b226-4436-a49d-590b34a1f4a8");
    public static Guid DRAFT_APPROVED_FOLDERID = new Guid("070510e7-33e8-4de4-b326-bc787cad7914");
    public static Guid DRAFT_REJECTED_FOLDERID = new Guid("17257b51-7f35-4955-9015-ab314ab75d84");
    public static Guid DRAFT_CANCELED_FOLDERID = new Guid("f69b5ded-63f9-4114-a9b8-db957a05c39d");
    public static Guid DRAFT_SUSPENDED_FOLDERID = new Guid("bf7750b6-f7ee-4adf-ae26-eb6bec9cc073");

    public static Guid APPROVAL_FOLDERID = new Guid("3d2074a6-c591-40bd-b8d5-f92072936dac");
    public static Guid APPROVAL_ONGOING_FOLDERID = new Guid("d1bb9d4e-a1f1-4440-99be-302720d390d9");
    public static Guid APPROVAL_APPROVED_FOLDERID = new Guid("b7c32ed6-8dc5-475b-b577-06322adfa4f7");
    public static Guid APPROVAL_REJECTED_FOLDERID = new Guid("76a4976d-4f58-4c88-8895-0f5c6a909fdc");

    public static Guid REFEREE_FOLDERID = new Guid("deba262f-79c4-4d12-8b7b-721c5e193a2d");
    public static Guid REFEREE_APPROVED_FOLDERID = new Guid("f37ce85a-b2a2-42a0-b6ca-5cc4ed1e18d4");
    public static Guid REFEREE_REJECTED_FOLDERID = new Guid("6d93074a-87c1-4bbd-84e6-9ba374a0bcfe");
    public static Guid REFEREE_CANCELED_FOLDERID = new Guid("32b1de86-874e-44ca-bfcc-eea35b7b3a03");

    public static Guid CIRCULATION_FOLDERID = new Guid("f496dec4-9fd4-4144-83a9-0c07521c0dba");
    public static Guid CIRCULATION_APPROVED_FOLDERID = new Guid("872b792b-0f12-4bb1-8be8-22bc302d6b80");
    public static Guid CIRCULATION_REJECTED_FOLDERID = new Guid("ecbb8dcb-dddd-4111-9b61-cabff15c7453");

    public static Guid TEMP_FOLDERID = new Guid("97f176e5-efca-4e6f-b799-eee0172578d8");
    public static Guid OPTION_FOLDERID = new Guid("c73d3199-bafa-4cc5-b3ab-00b9129ddff4");

	public AppFolderDataSource()
	{
	}

    public List<FolderItem> GetFolders()
    {
        List<FolderItem> folders = new List<FolderItem>();
        List<ApprovalUserFolder> subFolders;

        Guid domainId = WebUser.CurrentUser.DomainID;
        Guid domainUserId = WebUser.CurrentUser.DomainUserID;
        string userAccount = WebUser.CurrentUser.UserAccount;

        // 사용자 정의 폴더 정보 로드
        ApprovalUserFolder rootFolder = new ApprovalUserFolder(Guid.Empty, domainUserId);
        rootFolder.LoadApprovalSubFolders();

        // 새문서 갯수 정보 로드
        ApprovalDocuments documents = new ApprovalDocuments(domainId, userAccount);
        documents.LoadApprovalPersonCount();

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        FolderItem item = new FolderItem(Guid.Empty, Guid.Empty, Resources.Approval.AppBox_Draft, 0, 0, 0, "");     // 기안문서 폴더
        folders.Add(item);
        {
            item = new FolderItem(Guid.Empty, DRAFT_FOLDERID, Resources.Approval.AppBox_Draft_1,     // 기안한 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT, false), 1, "approval01.png");
            folders.Add(item);
            item = new FolderItem(Guid.Empty, DRAFT_APPROVED_FOLDERID, Resources.Approval.AppBox_Draft_2,     // 승인된 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_APPROVED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_APPROVED, Guid.Empty, false), 1, "approval02.png");
            folders.Add(item);
            {
                // 승인된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.DRAFT_APPROVED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(DRAFT_APPROVED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_APPROVED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_APPROVED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, DRAFT_REJECTED_FOLDERID, Resources.Approval.AppBox_Draft_3,     // 반려된 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_REJECTED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_REJECTED, Guid.Empty, false), 1, "approval03.png");
            folders.Add(item);
            {
                // 반려된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.DRAFT_REJECTED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(DRAFT_REJECTED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_REJECTED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_REJECTED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, DRAFT_CANCELED_FOLDERID, Resources.Approval.AppBox_Draft_4,     // 취소된 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_CANCELED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_CANCELED, Guid.Empty, false), 1, "approval10.png");
            folders.Add(item);
            {
                // 취소된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.DRAFT_CANCELED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(DRAFT_CANCELED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_CANCELED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_CANCELED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            if (AppSetting.ApvSuspendedStatus)
            {
                item = new FolderItem(Guid.Empty, DRAFT_SUSPENDED_FOLDERID, Resources.Approval.AppBox_Draft_5,     // 보류된 문서함,
                    documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_SUSPENDED, Guid.Empty),
                    documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.DRAFT_SUSPENDED, Guid.Empty, false), 1, "approval13.png");
                folders.Add(item);
            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        item = new FolderItem(Guid.Empty, Guid.Empty, Resources.Approval.AppBox_Decision, 0, 0, 0, "");     // 결재문서 폴더
        folders.Add(item);
        {
            item = new FolderItem(Guid.Empty, APPROVAL_FOLDERID, Resources.Approval.AppBox_Decision_1,     // 결재할 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL, false), 1, "approval04.png");
            folders.Add(item);
            item = new FolderItem(Guid.Empty, APPROVAL_ONGOING_FOLDERID, Resources.Approval.AppBox_Decision_2,     // 결재중 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_ING),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_ING, false), 1, "approval12.png");
            folders.Add(item);
            item = new FolderItem(Guid.Empty, APPROVAL_APPROVED_FOLDERID, Resources.Approval.AppBox_Decision_3,     // 승인한 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_APPROVED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_APPROVED, Guid.Empty, false), 1, "approval05.png");
            folders.Add(item);
            {
                // 승인한 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.APPROVAL_APPROVED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(APPROVAL_APPROVED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_APPROVED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_APPROVED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, APPROVAL_REJECTED_FOLDERID, Resources.Approval.AppBox_Decision_4,     // 반려한 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_REJECTED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_REJECTED, Guid.Empty, false), 1, "approval06.png");
            folders.Add(item);
            {
                // 반려한 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.APPROVAL_REJECTED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(APPROVAL_REJECTED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_REJECTED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.APPROVAL_REJECTED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        item = new FolderItem(Guid.Empty, Guid.Empty, Resources.Approval.AppBox_Forwarding, 0, 0, 0, "");       // 참조 문서함
        folders.Add(item);
        {
            item = new FolderItem(Guid.Empty, REFEREE_FOLDERID, Resources.Approval.AppBox_Forwarding_1,      // 참조 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE, false), 1, "approval09.png");
            folders.Add(item);
            item = new FolderItem(Guid.Empty, REFEREE_APPROVED_FOLDERID, Resources.Approval.AppBox_Forwarding_2,      // 승인된 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_APPROVED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_APPROVED, Guid.Empty, false), 1, "approval05.png");
            folders.Add(item);
            {
                // 승인된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.REFEREE_APPROVED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(REFEREE_APPROVED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_APPROVED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_APPROVED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, REFEREE_REJECTED_FOLDERID, Resources.Approval.AppBox_Forwarding_3,      // 반려된 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_REJECTED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_REJECTED, Guid.Empty, false), 1, "approval06.png");
            folders.Add(item);
            {
                // 반려된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.REFEREE_REJECTED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(REFEREE_REJECTED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_REJECTED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_REJECTED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, REFEREE_CANCELED_FOLDERID, Resources.Approval.AppBox_Forwarding_4,      // 취소된 문서함,
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_CANCELED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_CANCELED, Guid.Empty, false), 1, "approval10.png");
            folders.Add(item);
            {
                // 취소된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.REFEREE_CANCELED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(REFEREE_CANCELED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_CANCELED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.REFEREE_CANCELED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        item = new FolderItem(Guid.Empty, Guid.Empty, Resources.Approval.AppBox_Routing, 0, 0, 0, "");      // 회람 수신함
        folders.Add(item);
        {
            item = new FolderItem(Guid.Empty, CIRCULATION_FOLDERID, Resources.Approval.AppBox_Routing_1,    // 회람 수신함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION, false), 1, "approval11.png");
            folders.Add(item);
            item = new FolderItem(Guid.Empty, CIRCULATION_APPROVED_FOLDERID, Resources.Approval.AppBox_Routing_2,    // 승인된 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_APPROVED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_APPROVED, Guid.Empty, false), 1, "approval05.png");
            folders.Add(item);
            {
                // 승인된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.CIRCULATION_APPROVED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(CIRCULATION_APPROVED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_APPROVED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_APPROVED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }
            item = new FolderItem(Guid.Empty, CIRCULATION_REJECTED_FOLDERID, Resources.Approval.AppBox_Routing_3,    // 반려된 문서함
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_REJECTED, Guid.Empty),
                documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_REJECTED, Guid.Empty, false), 1, "approval06.png");
            folders.Add(item);
            {
                // 반려된 문서함 하위 폴더 로드
                subFolders = rootFolder.GetSubFolders(ApprovalDocuments.EnumDocumentType.CIRCULATION_REJECTED);
                foreach (ApprovalUserFolder folder in subFolders)
                {
                    item = new FolderItem(CIRCULATION_REJECTED_FOLDERID, folder.Id, folder.Name,
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_REJECTED, folder.Id),
                        documents.GetApprovalPersonCount(ApprovalDocuments.EnumDocumentType.CIRCULATION_REJECTED, folder.Id, false), 2, "folder_16.gif");
                    folders.Add(item);
                }
            }

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            item = new FolderItem(Guid.Empty, TEMP_FOLDERID, Resources.Approval.AppBox_Temp, 0, 0, 0, "approval07.png");        // 임시 보관함
            folders.Add(item);
            item = new FolderItem(Guid.Empty, OPTION_FOLDERID, Resources.Approval.AppBox_Preferences, 0, 0, 0, "approval08.png");       // 환경 설정
            folders.Add(item);
        }

        return folders;
    }
    
}