using AutoMapper;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using System.Collections.Generic;

namespace skydiveLogs_api.Controllers
{
    public class JumpTypeController : Base
    {
        #region Public Constructors

        public JumpTypeController(IJumpTypeService jumpTypeService,
                                  IMapper mapper)
        {
            _jumpTypeService = jumpTypeService;
            _mapper = mapper;
        }

        #endregion Public Constructors

        #region Public Methods

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

        // 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));
        }

        #endregion Public Methods

        #region Private Fields

        private readonly IJumpTypeService _jumpTypeService;
        private readonly IMapper _mapper;

        #endregion Private Fields
    }
}