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

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

        public HomeBannerController(IHomeBannerService homeBannerService, IMapper mapper)
        {
            _homeBannerService = homeBannerService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult HomeBannerList()
        {
            var value = _homeBannerService.TGetListAll();
            var result = _mapper.Map<List<ResultHomeBannerDto>>(value);
            return Ok(result);
        }

        [HttpPost]
        public IActionResult CreateHomeBanner(CreateHomeBannerDto createHomeBannerDto)
        {
            var value = _mapper.Map<HomeBanner>(createHomeBannerDto);
            _homeBannerService.TAdd(value);
            return Ok("Banner Bilgisi Eklendi");
        }

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

        [HttpPut]
        public IActionResult UpdateHomeBanner(UpdateHomeBannerDto updateHomeBannerDto)
        {
            var value = _mapper.Map<HomeBanner>(updateHomeBannerDto);
            _homeBannerService.TUpdate(value);
            return Ok("Banner Alanı Güncellendi");
        }

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