using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using chapitre5_aspnet_core_bookshop.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace chapitre5_aspnet_core_bookshop.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LibrairieController : ControllerBase
    {
        private readonly Services.ILibrairieService service;

        public LibrairieController(Services.ILibrairieService service)
        {
            this.service = service;
        }

        // GET: api/Librairie
        [HttpGet]
        public JsonResult Get()
        {
            Ouvrage[] records = service.GetOuvrages().ToArray();
            int total = records.Length;
            return new JsonResult(new { records, total });
        }

        // GET: api/Librairie/5
        [HttpGet("{id}", Name = "Get")]
        public Ouvrage Get(int id)
        {
            Services.LibairieService lib = new Services.LibairieService();
            return lib.GetOuvrages().Find(m => m.ID == id);
        }

        // POST: api/Librairie
        [HttpPost]
        public void Post([FromBody] Ouvrage value)
        {
        }

        // PUT: api/Librairie/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] Ouvrage value)
        {
        }

        // DELETE: api/ApiWithActions/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
