using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using rockfishCore.Models;
using rockfishCore.Util;


namespace rockfishCore.Controllers
{
    [Produces("application/json")]
    [Route("api/ops")]
    [Authorize]
    public class OpsController : Controller
    {
        private readonly rockfishContext _context;

        public OpsController(rockfishContext context)
        {
            _context = context;
        }


        //status of ops
        [HttpGet("status/{service}")]
        public dtoOpsStatus GetOpsStatus([FromRoute] string service)
        {
            dtoOpsStatus Ret = new dtoOpsStatus();


            try
            {
                switch (service)
                {
                    case "MailMirror":
                        Ret.Status = RfMail.MailIsMirroringProperly();
                        break;
                    case "AyaNovaSite":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://www.ayanova.com/", "Ground Zero Tech-Works Inc.");
                        break;
                    case "APISite":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://api.ayanova.com/", "WorkorderTypes Enumeration");
                        break;
                    case "ContactForm":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/contact", "Contact.Email");
                        break;
                    case "RequestForm":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/request", "Contact.Email");
                        break;
                    case "RequestLiteForm":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/requestlite", "Contact.Email");
                        break;
                    case "Subversion":
                        Ret.Status = OpsDiagnostics.CheckWebsite("http://svn.helloayanova.com:3343/csvn/login/auth", "Subversion Edge");
                        break;
                    case "Forum":
                        Ret.Status = OpsDiagnostics.CheckWebsite("http://forum.ayanova.com/", "AyaNova support resources");
                        break;
                    case "DevOps":
                        Ret.Status = OpsDiagnostics.CheckWebsite("https://test.helloayanova.com/api/v8/", "AyaNova server");
                        break;
                    case "Backup":
                        Ret.Status = OpsDiagnostics.VerifyBackups();
                        break;
                    default:
                        Ret.Status = false;
                        Ret.ServiceCheckError = $"Unknown service: \"{service}\"";
                        break;

                }

            }
            catch (Exception ex)
            {
                Ret.ServiceCheckError += $"{service}: {ex.Message}\r\n";
            }


            // try
            // {
            //     Ret.MailMirrorOK = RfMail.MailIsMirroringProperly();
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Mail mirror: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.AyaNovaSiteOK = OpsDiagnostics.CheckWebsite("https://www.ayanova.com/", "Ground Zero Tech-Works Inc.");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"AyaNova site: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.APISiteOK = OpsDiagnostics.CheckWebsite("https://api.ayanova.com/", "WorkorderTypes Enumeration");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"API site: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.ContactFormOK = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/contact", "Contact.Email");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Contact form: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.RequestFormOK = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/request", "Contact.Email");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Request form: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.RequestLiteFormOK = OpsDiagnostics.CheckWebsite("https://contact.ayanova.com/requestlite", "Contact.Email");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"RequestLite form: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.SubversionOK = OpsDiagnostics.CheckWebsite("http://svn.helloayanova.com:3343/csvn/login/auth", "Subversion Edge");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Subversion: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.ForumOK = OpsDiagnostics.CheckWebsite("http://forum.ayanova.com/", "AyaNova support resources");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Forum: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.DevOpsOK = OpsDiagnostics.CheckWebsite("https://test.helloayanova.com/api/v8/", "AyaNova server");
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"DevOps: {ex.Message}\r\n";
            // }

            // try
            // {
            //     Ret.BackupOK = OpsDiagnostics.VerifyBackups();
            // }
            // catch (Exception ex)
            // {
            //     Ret.OpsCheckError += $"Backup: {ex.Message}\r\n";
            // }

            return Ret;
        }

        public class dtoOpsStatus
        {
            public bool Status;
            public string ServiceCheckError;

            public dtoOpsStatus()
            {
                Status = false;
                ServiceCheckError = string.Empty;
            }
        }


    }//eoc
}//eons