using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using AipGateway.AIP;

namespace AipGateway.Test
{
    class Program
    {
        private static AipFileManager _aipFileManager;

        static void Main(string[] args)
        {
            AipConfig aipConfig = new AipConfig
            {
                AppName        = ConfigurationManager.AppSettings["AppName"], // 어플리케이션 이름
                AppVersion     = ConfigurationManager.AppSettings["AppVersion"], // 어플리케이션 버전
                ClientId       = ConfigurationManager.AppSettings["aip:ClientId"], // 어플리케이션 ID(클라이언트 ID)
                TenantId       = ConfigurationManager.AppSettings["aip:TenantId"], // 디렉토리(테넌트) ID
                MipData        = ConfigurationManager.AppSettings["aip:MipData"], // Mip Data Path
                Domain         = ConfigurationManager.AppSettings["aip:Domain"], // Domain
                EMail          = ConfigurationManager.AppSettings["aip:EMail"], // User E-Mail
                SecretValue    = ConfigurationManager.AppSettings["aip:SecretValue"], // 인증 비밀번호
                CertThumbPrint = ConfigurationManager.AppSettings["aip:CertThumbPrint"] // 인증서 지문
            };
            string tempLoginType = ConfigurationManager.AppSettings["aip:LoginType"];
            AipAuthLoginType loginType = (AipAuthLoginType)Enum.Parse(typeof(AipAuthLoginType), tempLoginType, true);
            aipConfig.LoginType = loginType;

            _aipFileManager = new AipFileManager(aipConfig);

            _aipFileManager.Initialize();
            _aipFileManager.CreateProfile();
            _aipFileManager.CreateEngine();

            Console.WriteLine("SensitivityLabels=======================================================================");
            List<AipLabel> aipLabels = _aipFileManager.SensitivityLabels();
            foreach (var label in aipLabels)
            {
                Console.WriteLine(string.Format("ID: {0}, NAME: {1}", label.Id, label.Name));
                if (label.Children.Count > 0)
                {
                    foreach (AipLabel child in label.Children)
                    {
                        Console.WriteLine(string.Format("\tID: {0}, NAME: {1}", child.Id, child.Name));
                    }
                }
            }
            Console.WriteLine("ListSensitivityLabels=======================================================================");

            List<AipLabel> labels2 = _aipFileManager.ListSensitivityLabels();
            foreach (var v in labels2)
            {
                Console.WriteLine("Label List: {0}, {1}, {2}", v.Id, v.Name, v.IsActive);
                if (v.Children.Count > 0)
                {
                    foreach (AipLabel child in v.Children)
                    {
                        Console.WriteLine("\tID: {0}, NAME: {1}", child.Id, child.Name);
                    }
                }
            }
            Console.WriteLine("GetTemplates=======================================================================");
            List<AipTemplate> templates = _aipFileManager.GetTemplates();
            foreach (var v in templates)
            {
                Console.WriteLine("Template: {0}, {1}, {2}", v.Id, v.Name, v.Description);
            }
            Console.WriteLine("=======================================================================");

            Console.WriteLine("Press a key to continue...");
            Console.ReadKey();
        }
    }
}
