﻿using ArragroCMS.Core.Web.DataTransformationObjects;
using ArragroCMS.BusinessLayer.Domains;
using ArragroCMS.BusinessLayer.Data.Entities;
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
using ArragroCMS.BusinessLayer.Interfaces.CacheDomains;

namespace ArragroCMS.BusinessLayer.Resolvers
{
    public class ContentTagsResolver : IValueResolver<Content, ContentDtoBase, List<string>>
    {
        private readonly ICacheTags _tags;

        public ContentTagsResolver(ICacheTags tags)
        {
            _tags = tags;
        }

        public List<string> Resolve(Content source, ContentDtoBase destination, List<string> member, ResolutionContext context)
        {
            var tags = _tags.GetUrlRouteTagsAsync(source.UrlRouteId).Result.Select(x => x.Name);
            return tags.ToList();
        }
    }
}
