﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HartmannSolutions.Domain.Services.Recaptcha;

namespace HartmannSolutions.Web.Mvc.Extensions
{
    public static class ModelStateExtensions
    {
        public static void AddRecaptchaErrors(this ModelStateDictionary modelState, RecaptchaResponse recaptchaResponse)
        {
            if (recaptchaResponse?.ErrorCodes == null) return;

            foreach (var errorCode in recaptchaResponse.ErrorCodes)
            {
                modelState.AddModelError("ReCAPTCHA", errorCode.ToString());
            }
        }
    }
}