using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApiExample2.Business;
using WebApiExample2.Data.Model;

/* 
 * The following namespace contains the one and only controller
 * of our Web API
 * It can be called via HTTP/HTTPS to perform actions on books
 * 
 */
namespace WebApiExample2.Controllers
{
    [Route("api/[controller]")]//Our route
    [ApiController]
    public class BooksController : ControllerBase
    {
        private readonly IBookService bookService;

        /*
         * 
         * Constructor injection
         * The book service is injected as an interface
         * by Microsoft's Dependency Injection framework
         * 
         */
         
        public BooksController(IBookService bookService)
        {
            this.bookService = bookService;
        }

        // GET api/books
        [HttpGet]
        public ActionResult<Book[]> Get()
        {
            return bookService.GetBook();
        }

        // e.g. GET api/books/5
        [HttpGet("{id}")]
        public ActionResult<Book> Get(int id)
        {
            return bookService.GetBook(id);            
        }

        // POST api/books
        [HttpPost]
        public void Post([FromBody] Book book)
        {           
            bookService.CreateBook(book);
        }

        // e.g. PUT api/books/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
            throw new NotImplementedException();
        }

        // e.g. DELETE api/books/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
            throw new NotImplementedException();
        }
    }
}
