﻿using System.Linq;
using System.Web;
using System.Web.Routing;

namespace WebBlocks.Application.Mvc.Routes
{
    public class CultureIsValid : IRouteConstraint
    {
        private readonly string[] _cultures;

        public CultureIsValid(string[] cultures)
        {
            _cultures = cultures;
        }

        public bool Match(HttpContextBase httpContext, 
            Route route, 
            string parameterName, 
            RouteValueDictionary values,
            RouteDirection routeDirection)
        {
            var currentCulture = values[parameterName];

            if (currentCulture != null)
            {
                return _cultures.Contains(currentCulture);
            }

            return false;
        }
    }
}
