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

namespace ContosoPizzaLibraryV2
{
    [DataContract(Namespace="http://contoso/pizza/v2")]
    public class Pizza
    {
        [DataMember]
        public string PizzaId;
        [DataMember]
        public string PizzaName;
        [DataMember]
        public double PizzaPrice;
    }

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

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

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

    [ServiceBehavior(Namespace="http://contoso/pizza/v2",
        InstanceContextMode=InstanceContextMode.Single)]
    public class PizzaServiceV2 : IPizzaService
    {
        List<Pizza> pizzas = new List<Pizza>()
        {
            new Pizza() { PizzaId = "1", PizzaName = "Margarita", PizzaPrice = 14.95 },
            new Pizza() { PizzaId = "2", PizzaName = "Hawaiin", PizzaPrice = 17.95 },
            new Pizza() { PizzaId = "3", PizzaName = "Pepperoni", PizzaPrice = 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.PizzaId.Equals(id));
        }

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

}
