using CloudBuilder.Core.DatabaseAccessor.Entity;
using CloudBuilder.Core.Service;
using CloudBuilder.Security.Data;
using CloudBuilder.Security.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudBuilder.Security.Service
{
    public class YesNoPolicyService : IYesNoPolicyService
    {
        private readonly IApplicationService service;

        public YesNoPolicyService(IApplicationService service)
        {
            this.service = service;
        }

        [AllowAnonymous]
        [HttpPost]
        public SelectOption[] FindSelectOption(bool blank)
        {
            YesNoPolicy policy = YesNoPolicy.GetInstance();
            string[] values = policy.GetValues();
            List<SelectOption> l = new List<SelectOption>();

            SelectOption selectOption;
            if (blank)
            {
                selectOption = new SelectOption();
                l.Add(selectOption);
            }

            foreach (string value in values)
            {
                selectOption = new SelectOption();
                selectOption.BindValue = value;
                selectOption.DisplayName = policy.ComposeMessage(value, service.Locale);
                l.Add(selectOption);
            }
            return l.ToArray();
        }

    }
}
