using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NewWebApi.Schema;

namespace NewWebApi.Controllers
{
    public class WebApiController : Controller
    {
        private Query query;

        public WebApiController()
        {
            query = new Query();
        }

        [Route("book/{id}")]
        [HttpGet]
        public ActionResult GetBook(int id)
        {
            var book = query.GeBook(id);
            if (book == null)
            {
                return NotFound();
            }
            return Ok(book);
        }

        [Route("books")]
        [HttpGet]
        public ActionResult GetBooks()
        {
            var book = query.GeBooks();
            if (book == null)
            {
                return NotFound();
            }
            return Ok(book);
        }

        [Route("author/{id}")]
        [HttpGet]
        public ActionResult GetAuthor(int id)
        {
            var author = query.GeAuthor(id);
            if (author == null)
            {
                return NotFound();
            }
            return Ok(author);
        }

        [Route("authors")]
        [HttpGet]
        public ActionResult GetAuthors()
        {
            var authors = query.GeAuthors();
            if (authors == null)
            {
                return NotFound();
            }
            return Ok(authors);
        }
    }
}