using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace ContosoPizzaLibrary
{
    [DataContract(Namespace="http://contoso/pizza")]
    public class Pizza
    {
        [DataMember]
        public string Id;
        [DataMember]
        public string Name;
        [DataMember]
        public double Price;
    }

    [ServiceContract(Namespace="http://contoso/pizza")]
    public interface IPizzaService
    {
        [WebGet(UriTemplate="")]
        [OperationContract]
        List<Pizza> GetPizzaMenu();

        [WebGet(UriTemplate="{id}")]
        [OperationContract]
        Pizza GetPizza(string id);

        [WebInvoke(UriTemplate="orders/{id}",Method="POST")]
        [OperationContract]
        void OrderPizza(string id);
    }

    [ServiceBehavior(Namespace="http://contoso/pizza",
        InstanceContextMode=InstanceContextMode.Single)]
    public class PizzaService : IPizzaService
    {
        List<Pizza> pizzas = new List<Pizza>()
        {
            new Pizza() { Id = "1", Name = "Margarita", Price = 14.95 },
            new Pizza() { Id = "2", Name = "Hawaiin", Price = 17.95 },
            new Pizza() { Id = "3", Name = "Pepperoni", Price = 17.95 }
        };

        #region IPizzaService Members

        public List<Pizza> GetPizzaMenu()
        {
            Console.WriteLine("GetPizzaMenu called.");
            return this.pizzas;
        }

        public Pizza GetPizza(string id)
        {
            Console.WriteLine("GetPizza called with id: {0}", id);
            return this.pizzas.Find(p => p.Id.Equals(id));
        }

        public void OrderPizza(string id)
        {
            Console.WriteLine("You ordered pizza: {0}", id);
        }
        #endregion
    }

}
