using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AzureRestApi.Services
{
    public class OptionService : IHostedService
    {
        private readonly ILogger<OptionService> _logger;
        private readonly CreatedOnDateService _createdOnDateService;
        private readonly DeploymentTypeService _deploymentTypeService;

        public OptionService(ILogger<OptionService> logger, CreatedOnDateService createdOnDateService, DeploymentTypeService deploymentTypeService)
        {
            _logger = logger;
            _createdOnDateService = createdOnDateService;
            _deploymentTypeService = deploymentTypeService;
        }

        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var rule = new Rule("[yellow]Cloud Egineering Console App[/]");
            AnsiConsole.Write(rule);

            Console.WriteLine("-- This couldn't be done with Powershell, so here we are.... ");
            Console.WriteLine();

            var choices = new[]
                            {
                                    "Update missing CreatedOnDate tags.",
                                    "Update missing IaC Deployment type tags.",
                                    "Exit"
                                };
            var result = AnsiConsole.Prompt(new SelectionPrompt<string>()
                                                .Title("Select what you want to do:")
                                                .PageSize(10)
                                                .MoreChoicesText("[grey](Move up and down to reveal more choices)[/]")
                                                .AddChoices(choices));

            if (result == choices[0])
            {
                await _createdOnDateService.SetCreatedOnDateTags(true);
            }
            else if (result == choices[1])
            {
                await _deploymentTypeService.CheckDeploymentTypes();
            }

            rule = new Rule("[yellow]Done. Bye.[/]");
            AnsiConsole.Write(rule);
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

    }
}
