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

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

        public TunnelController(ITunnelService tunnelService,
                                IMapper mapper)
        {
            _tunnelService = tunnelService;
            _mapper = mapper;
        }

        #endregion Public Constructors

        #region Public Methods

        // GET: api/Tunnel
        [HttpGet]
        [EnableCors]
        public IEnumerable<TunnelResp> Get()
        {
            var result = _tunnelService.GetAllTunnels();
            return _mapper.Map<IEnumerable<TunnelResp>>(result);
        }

        // GET: api/Tunnel/5
        [HttpGet("{id}")]
        [EnableCors]
        public TunnelResp Get(int id)
        {
            var result = _tunnelService.GetTunnelById(id);
            return _mapper.Map<TunnelResp>(result);
        }

        #endregion Public Methods

        #region Private Fields

        private readonly ITunnelService _tunnelService;
        private readonly IMapper _mapper;

        #endregion Private Fields
    }
}