using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;

namespace Umbraco.Cms.Infrastructure.Persistence.Mappers;

// TODO: This mapper is actually very useless because the only time it would ever be used is when trying to generate a strongly typed query
// on an IContentBase object which is what exposes ISimpleContentType, however the queries that we execute in the content repositories don't actually
// join on the content type table. The content type data is resolved outside of the query so the end result of the query that is generated by using
// this mapper will either fail or the syntax will target umbracoNode which will be filtering on the actual content NOT the content type.
// I'm leaving this here purely because the ExpressionTests rely on this which is fine for testing that the expressions work, but note that this
// resulting query will not.
[MapperFor(typeof(ISimpleContentType))]
[MapperFor(typeof(SimpleContentType))]
public sealed class SimpleContentTypeMapper : BaseMapper
{
    public SimpleContentTypeMapper(Lazy<ISqlContext> sqlContext, MapperConfigurationStore maps)
        : base(sqlContext, maps)
    {
    }

    protected override void DefineMaps()
    {
        // There is no reason for using ContentType here instead of SimpleContentType, in fact the underlying DefineMap call does nothing with the first type parameter
        DefineMap<ContentType, NodeDto>(nameof(ContentType.Id), nameof(NodeDto.NodeId));
        DefineMap<ContentType, NodeDto>(nameof(ContentType.Key), nameof(NodeDto.UniqueId));
        DefineMap<ContentType, NodeDto>(nameof(ContentType.Name), nameof(NodeDto.Text));
        DefineMap<ContentType, ContentTypeDto>(nameof(ContentType.Alias), nameof(ContentTypeDto.Alias));
        DefineMap<ContentType, ContentTypeDto>(nameof(ContentType.Icon), nameof(ContentTypeDto.Icon));
        DefineMap<ContentType, ContentTypeDto>(nameof(ContentType.IsContainer), nameof(ContentTypeDto.IsContainer));
        DefineMap<ContentType, ContentTypeDto>(nameof(ContentType.AllowedAsRoot), nameof(ContentTypeDto.AllowAtRoot));
        DefineMap<ContentType, ContentTypeDto>(nameof(ContentType.IsElement), nameof(ContentTypeDto.IsElement));
    }
}
