using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;

using AutoMapper;

using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Model;


namespace skydiveLogs_api.Controllers
{
    public class JumpTypeController : Base
    {
        public JumpTypeController(IJumpTypeService jumpTypeService,
                                  IMapper mapper)
        {
            _jumpTypeService = jumpTypeService;
            _mapper = mapper;
        }

        // GET: api/JumpType
        [HttpGet]
        [EnableCors]
        public IEnumerable<JumpTypeResp> Get()
        {
            var result = _jumpTypeService.GetAllJumpTypes();
            return _mapper.Map<IEnumerable<JumpTypeResp>>(result);
        }

        // GET: api/JumpType/5
        [HttpGet("{id}")]
        [EnableCors]
        public JumpTypeResp Get(int id)
        {
            var result = _jumpTypeService.GetJumpTypeById(id);
            return _mapper.Map<JumpTypeResp>(result);
        }

        // POST: api/JumpType
        [HttpPost]
        [EnableCors]
        public void Post([FromBody] JumpTypeReq value)
        {
            _jumpTypeService.AddNewJumpType(_mapper.Map<JumpType>(value));
        }

        // PUT: api/JumpType/5
        [HttpPut("{id}")]
        [EnableCors]
        public void Put(int id, [FromBody] JumpTypeReq value)
        {
            _jumpTypeService.UpdateJumpType(id, _mapper.Map<JumpType>(value));
        }

        // DELETE: api/ApiWithActions/5
        [HttpDelete("{id}")]
        [EnableCors]
        public void Delete(int id)
        {
            _jumpTypeService.DeleteJumpTypeById(id);
        }

        private readonly IJumpTypeService _jumpTypeService;
        private readonly IMapper _mapper;
    }
}
