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

namespace BasicWithMessagesSample.Controllers
{
    public class ValuesController : ApiController
    {
        private List<string> data = new List<string>() { "elem1", "elem2" };

        // GET api/values
        public IEnumerable<string> Get()
        {
            return data; // new string[] { "value1", "value2" };
        }

        // 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]string value)
        {
            data.Add(value);
            return Request.CreateResponse(HttpStatusCode.Created);
        }

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

        // DELETE api/values/5
        public void Delete(int id)
        {
            data.RemoveAt(id);
        }
    }
}