using CMSMicroservice.Application.BlogPostCQ.Commands.PublishBlogPost;
using CMSMicroservice.Application.BlogPostCQ.Commands.ArchiveBlogPost;
using Google.Protobuf.WellKnownTypes;
using Mapster;
using ProtoBlogPost = CMSMicroservice.Protobuf.Protos.BlogPost;

namespace CMSMicroservice.WebApi.Common.Mappings;

public class BlogPostProfile : IRegister
{
    void IRegister.Register(TypeAdapterConfig config)
    {
        // PublishBlogPost: Command result → Proto response
        config.NewConfig<PublishBlogPostResult, ProtoBlogPost.PublishBlogPostResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message)
            .Map(dest => dest.PublishedAt, src => src.PublishedAt.HasValue
                ? Timestamp.FromDateTime(DateTime.SpecifyKind(src.PublishedAt.Value, DateTimeKind.Utc))
                : null);

        // ArchiveBlogPost: Command result → Proto response
        config.NewConfig<ArchiveBlogPostResult, ProtoBlogPost.ArchiveBlogPostResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message);
    }
}
