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

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

        public WorkProcessController(IWorkProcessService workProcessService, IMapper mapper)
        {
            _workProcessService = workProcessService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult WorkProcessList()
        {
            var value = _workProcessService.TGetListAll();
            var result = _mapper.Map<List<ResultWorkProcessDto>>(value);
            return Ok(result);
        }


        [HttpDelete("{id}")]
        public IActionResult DeleteWorkProcess(int id)
        {
            var value = _workProcessService.TGetByID(id);
            if (value != null)
            {
                _workProcessService.TDelete(value);
                return Ok("Çalışma Şekli Bilgisi Silindi");
            }
            return NotFound("Çalışma Şekli Bilgisi Bulunamadı");
        }

        [HttpPut]
        public IActionResult UpdateWorkProcess(UpdateWorkProcessDto updateWorkProcessDto)
        {
            var value = _mapper.Map<WorkProcess>(updateWorkProcessDto);
            _workProcessService.TUpdate(value);
            return Ok("Çalışma Şekli Bilgisi Güncellendi");
        }

        [HttpGet("{id}")]
        public IActionResult GetWorkProcess(int id)
        {
            var value = _workProcessService.TGetByID(id);
            if (value != null)
            {
                var result = _mapper.Map<ResultWorkProcessDto>(value);
                return Ok(result);
            }
            return NotFound("Çalışma Şekli Bilgisi Bulunamadı");
        }

        [HttpGet("ServiceStatusActive/{id}")]
        public IActionResult ServiceStatusActive(int id)
        {
            _workProcessService.TServiceStatusActive(id);
            return Ok("Çalışma Şekli Aktif Hale Getirildi");
        }

        [HttpGet("ServiceStatusPassive/{id}")]
        public IActionResult ServiceStatusPassive(int id)
        {
            _workProcessService.TServiceStatusPassive(id);
            return Ok("Çalışma Şekli Pasif Hale Getirildi");
        }
    }
}
