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

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

        /// <summary>
        /// Deletes a jump type by its ID.
        /// </summary>
        /// <param name="id">The jump type ID to delete.</param>
        [HttpDelete("{id}")]
        [EnableCors]
        public void Delete(int id)
        {
            _jumpTypeService.DeleteJumpTypeById(id);
        }

        /// <summary>
        /// Retrieves a list of all jump types.
        /// </summary>
        /// <returns>A collection of JumpTypeResp objects containing all jump types.</returns>
        [HttpGet]
        [EnableCors]
        public IEnumerable<JumpTypeResp> Get()
        {
            var result = _jumpTypeService.GetAllJumpTypes();
            return _mapper.Map<IEnumerable<JumpTypeResp>>(result);
        }

        /// <summary>
        /// Retrieves jump types used for tunnel operations.
        /// </summary>
        /// <returns>A collection of JumpTypeResp objects containing tunnel jump types.</returns>
        [HttpGet("tunnel")]
        [EnableCors]
        public IEnumerable<JumpTypeResp> GetForTunnel()
        {
            var result = _jumpTypeService.GetJumpTypesForTunnel();
            return _mapper.Map<IEnumerable<JumpTypeResp>>(result);
        }

        /// <summary>
        /// Retrieves a jump type by its ID.
        /// </summary>
        /// <param name="id">The jump type ID to retrieve.</param>
        /// <returns>A JumpTypeResp object containing the jump type details.</returns>
        [HttpGet("{id}")]
        [EnableCors]
        public JumpTypeResp Get(int id)
        {
            var result = _jumpTypeService.GetJumpTypeById(id);
            return _mapper.Map<JumpTypeResp>(result);
        }

        /// <summary>
        /// Adds a new jump type to the system.
        /// </summary>
        /// <param name="value">JumpTypeReq object containing the new jump type data.</param>
        [HttpPost]
        [EnableCors]
        public void Post([FromBody] JumpTypeReq value)
        {
            _jumpTypeService.AddNewJumpType(_mapper.Map<JumpType>(value));
        }

        /// <summary>
        /// Updates an existing jump type.
        /// </summary>
        /// <param name="id">The jump type ID to update.</param>
        /// <param name="value">JumpTypeReq object containing the updated jump type data.</param>
        [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
    }
}
