using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using FMSAdmin.Models;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using FMSAdmin.Data;
using System.Net.Mail;
using System.Net;
using FMSAdmin.Helpers;
using SelectPdf;

namespace FMSAdmin.Controllers {
    [ApiController]
    [ApiVersion("1")]
    [Route("api")]
    public class HomeController : Controller {
        private readonly ILogger<HomeController> _logger;
        private readonly FMSContext _context;
        private readonly StorageHelper _storage;

        public HomeController(
                ILogger<HomeController> logger,
                FMSContext context,
                StorageHelper storage
                ) {
            _logger = logger;
            _context = context;
            _storage = storage;
        }

        [HttpGet]
        public IActionResult Index() {
            return Content("api server");
        }


        [HttpGet("[action]")]
        public IActionResult EmailTest() {
            // 이메일 테스트
            using (var message = new MailMessage()) {
                // 받는사람
                message.To.Add(new MailAddress("테스트@gmail.com", "테스트"));

                // 보내는사람
                message.From = new MailAddress("hdc.icontrols.rnd1@gmail.com", "FMS");
                //message.CC.Add(new MailAddress("cc@email.com", "CC Name"));
                //message.Bcc.Add(new MailAddress("bcc@email.com", "BCC Name"));
                message.Subject = "이메일 인증 테스트";
                message.Body = "코드는 2390423 입니다.";
                message.IsBodyHtml = true;
                var smtp = new SmtpClient {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials = new NetworkCredential("hdc.icontrols.rnd1@gmail.com", "pwrd12#$"),
                    Timeout = 20000
                };
                smtp.Send(message);
            }
            return Content(":)");
        }

    }
}
