using AutoMapper;
using ConstructorApp.BusinessLayer.Abstract;
using ConstructorApp.DtoLayer.SliderDto;
using ConstructorApp.EntityLayer.Entities;
using Microsoft.AspNetCore.Mvc;

namespace ConstructorAppApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SliderController : ControllerBase
    {
        private readonly ISliderService _sliderService;
        private readonly IMapper _mapper;

        public SliderController(ISliderService sliderService, IMapper mapper)
        {
            _sliderService = sliderService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult SliderList()
        {
            var value = _sliderService.TGetListAll();
            var result = _mapper.Map<List<ResultSliderDto>>(value);
            return Ok(result);
        }

        [HttpPost]
        public IActionResult CreateSlider(CreateSliderDto createSliderDto)
        {
            var value = _mapper.Map<Slider>(createSliderDto);
            _sliderService.TAdd(value);
            return Ok("Slider Bilgisi Eklendi");
        }

        [HttpDelete("{id}")]
        public IActionResult DeleteSlider(int id)
        {
            var value = _sliderService.TGetByID(id);
            if (value != null)
            {
                _sliderService.TDelete(value);
                return Ok("Slider Bilgisi Silindi");
            }
            return NotFound("Slider Bilgisi Bulunamadı");
        }

        [HttpPut]
        public IActionResult UpdateSlider(UpdateSliderDto updateSliderDto)
        {
            var value = _mapper.Map<Slider>(updateSliderDto);
            _sliderService.TUpdate(value);
            return Ok("Slider Alanı Güncellendi");
        }

        [HttpGet("{id}")]
        public IActionResult GetSlider(int id)
        {
            var value = _sliderService.TGetByID(id);
            if (value != null)
            {
                var result = _mapper.Map<ResultSliderDto>(value);
                return Ok(result);
            }
            return NotFound("Slider Bilgisi Bulunamadı");
        }
    }
}
