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

namespace BasicWithObjects.Controllers
{
    public class Movie
    {
        public int Id { get; set; }
        public string Title { get; set; }
    }

    public class ValuesController : ApiController
    {
        private static List<Movie> data = new List<Movie>
        {
            new Movie { Id = 1, Title = "Spirited Away" },
            new Movie { Id = 2, Title = "Informator" },
            new Movie { Id = 3, Title = "Shawshank Redemption" }
        };

        // GET api/values
        public HttpResponseMessage Get()
        {
            return Request.CreateResponse(HttpStatusCode.OK, data);
        }

        // GET api/values/5
        public HttpResponseMessage Get(int id)
        {
            if (id < data.Count)
                return Request.CreateResponse(HttpStatusCode.OK, data[id]);
            else
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item not found");

        }

        // POST api/values
        public HttpResponseMessage Post([FromBody]Movie value)
        {
            if (value != null)
            {
                data.Add(value);
                return Request.CreateResponse(HttpStatusCode.Created, "Yuppi!");
            }
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Item not created");
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }
}