﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using ChinookWebAPIOData.Models;
using System.Web.OData.Builder;
using System.Web.OData.Extensions;
using ChinookWebAPIOData.Extensions;

namespace ChinookWebAPIOData
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Album>("Albums");
            builder.EntitySet<Artist>("Artists");
            builder.EntitySet<Customer>("Customers");
            builder.EntitySet<Employee>("Employees");
            builder.EntitySet<Genre>("Genres");
            builder.EntitySet<Invoice>("Invoices");
            builder.EntitySet<InvoiceLine>("InvoiceLines");
            builder.EntitySet<MediaType>("MediaTypes");
            builder.EntitySet<Playlist>("Playlists");
            builder.EntitySet<Track>("Tracks");

            builder.Namespace = "Chinook";

            var albumEntityType = builder.EntityType<Album>();

            var buyAction = albumEntityType.Action("Buy");
            buyAction.ReturnsFromEntitySet<Album>("Albums");


            config.MapODataServiceRoute(
                routeName: "ODataRoute",
                routePrefix: null,
                model: builder.GetEdmModel());
        }
    }
}
