using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Routing;
using System.Net.Http;

namespace RestApi
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "TablesApi",
                routeTemplate: "contexts/{context_id}/tables/{table_id}",
                defaults: new { controller = "Tables", table_id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "QueryApi",
                routeTemplate: "contexts/{context_id}/query",
                defaults: new { controller = "Query" }
            );

            config.Routes.MapHttpRoute(
                name: "JobsApi",
                routeTemplate: "jobs/{id}",
                defaults: new { controller = "Jobs", id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "ContextJobsApi",
                routeTemplate: "contexts/{context_id}/jobs",
                defaults: new { controller = "Jobs", action = "CreateJob", httpMethod = new HttpMethodConstraint(HttpMethod.Put) }
            );

            config.Routes.MapHttpRoute(
                name: "UsersApi",
                routeTemplate: "users/{keystone_id}",
                defaults: new { controller = "Users", keystone_id = RouteParameter.Optional }
            );
        }
    }
}
