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

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

        public ServiceController(IServiceService serviceService, IMapper mapper)
        {
            _serviceService = serviceService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult ServiceList()
        {
            var value = _serviceService.TGetListAll();
            var result = _mapper.Map<List<ResultServiceDto>>(value);
            return Ok(result);
        }


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

        [HttpPut]
        public IActionResult UpdateService(UpdateServiceDto updateServiceDto)
        {
            var value = _mapper.Map<Service>(updateServiceDto);
            _serviceService.TUpdate(value);
            return Ok("Hizmet Alanı Güncellendi");
        }

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

        [HttpGet("ServiceStatusActive/{id}")]
        public IActionResult ServiceStatusActive(int id)
        {
            _serviceService.TServiceStatusActive(id);
            return Ok("Servis Aktif Hale Getirildi");
        }

        [HttpGet("ServiceStatusPassive/{id}")]
        public IActionResult ServiceStatusPassive(int id)
        {
            _serviceService.TServiceStatusPassive(id);
            return Ok("Servis Pasif Hale Getirildi");
        }
    }
}
