using System.Threading.Tasks;
using API.Data;
using API.DTOs.Theme;
using API.Entities.Interfaces;
using API.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
[Authorize]
public class ColorScapeController : BaseApiController
{
    private readonly IUnitOfWork _unitOfWork;
    public ColorScapeController(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }
    /// 
    /// Returns the color scape for a series
    /// 
    /// 
    /// 
    [HttpGet("series")]
    public async Task> GetColorScapeForSeries(int id)
    {
        var entity = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(id, User.GetUserId());
        return GetColorSpaceDto(entity);
    }
    /// 
    /// Returns the color scape for a volume
    /// 
    /// 
    /// 
    [HttpGet("volume")]
    public async Task> GetColorScapeForVolume(int id)
    {
        var entity = await _unitOfWork.VolumeRepository.GetVolumeDtoAsync(id, User.GetUserId());
        return GetColorSpaceDto(entity);
    }
    /// 
    /// Returns the color scape for a chapter
    /// 
    /// 
    /// 
    [HttpGet("chapter")]
    public async Task> GetColorScapeForChapter(int id)
    {
        var entity = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(id, User.GetUserId());
        return GetColorSpaceDto(entity);
    }
    private ActionResult GetColorSpaceDto(IHasCoverImage entity)
    {
        if (entity == null) return Ok(ColorScapeDto.Empty);
        return Ok(new ColorScapeDto(entity.PrimaryColor, entity.SecondaryColor));
    }
}