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

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

        public CompanyInfoVideoController(ICompanyInfoVideoService companyInfoVideoService, IMapper mapper)
        {
            _companyInfoVideoService = companyInfoVideoService;
            _mapper = mapper;
        }

        [HttpGet]
        public IActionResult CompanyInfoVideoList()
        {
            var value = _companyInfoVideoService.TGetListAll();
            var result = _mapper.Map<List<ResultCompanyInfoVideoDto>>(value);
            return Ok(result);
        }

        [HttpDelete("{id}")]
        public IActionResult DeleteCompanyInfoVideo(int id)
        {
            var value = _companyInfoVideoService.TGetByID(id);
            if (value != null)
            {
                _companyInfoVideoService.TDelete(value);
                return Ok("Hakkımızda Video Bilgisi Silindi");
            }
            return NotFound("Hakkımızda Video Bilgisi Bulunamadı");
        }

        [HttpPut]
        public IActionResult UpdateCompanyInfoVideo(UpdateCompanyInfoVideoDto updateCompanyInfoVideoDto)
        {
            var value = _mapper.Map<CompanyInfoVideo>(updateCompanyInfoVideoDto);
            _companyInfoVideoService.TUpdate(value);
            return Ok("Hakkımızda Video  Güncellendi");
        }

        [HttpGet("{id}")]
        public IActionResult GetCompanyInfoVideo(int id)
        {
            var value = _companyInfoVideoService.TGetByID(id);
            if (value != null)
            {
                var result = _mapper.Map<ResultCompanyInfoVideoDto>(value);
                return Ok(result);
            }
            return NotFound("Hakkımızda Video Bilgisi Bulunamadı");
        }
    }
}
