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

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

        public TestimonialController(ITestimonialService testimonialService, IMapper mapper)
        {
            _testimonialService = testimonialService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult TestimonialList()
        {
            var value = _testimonialService.TGetListAll();
            var result = _mapper.Map<List<ResultTestimonialDto>>(value);
            return Ok(result);
        }

        [HttpPost]
        public IActionResult CreateTestimonial(CreateTestimonialDto createTestimonialDto)
        {
            var value = _mapper.Map<Testimonial>(createTestimonialDto);
            _testimonialService.TAdd(value);
            return Ok("Yorum Bilgisi Eklendi");
        }

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

        [HttpPut]
        public IActionResult UpdateTestimonial(UpdateTestimonialDto updateTestimonialDto)
        {
            var value = _mapper.Map<Testimonial>(updateTestimonialDto);
            _testimonialService.TUpdate(value);
            return Ok("Yorum Alanı Güncellendi");
        }

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

        [HttpGet("TestimonialStatusActive/{id}")]
        public IActionResult TestimonialStatusActive(int id)
        {
            _testimonialService.TTestimonialStatusActive(id);
            return Ok("Ürün Kategorisi Aktif Hale Getirildi");
        }

        [HttpGet("TestimonialStatusPassive/{id}")]
        public IActionResult TestimonialStatusPassive(int id)
        {
            _testimonialService.TTestimonialStatusPassive(id);
            return Ok("Ürün Kategorisi Pasif Hale Getirildi");
        }

        [HttpGet("CountAll")]
        public IActionResult CountAll()
        {
            return Ok(_testimonialService.TCountAll());
        }
    }
}
