using AutoMapper;
using Qusion.Cms.Core.Domain;
using Qusion.Cms.Site;
using Qusion.Cms.Site.Core;
using Qusion.Framework;

namespace Qusion.WebApp.Areas.Qusion.Models.Pages
{
    public class PageProfile : Profile
    {
        protected override void Configure()
        {
     
            
            Mapper.CreateMap<Page, PageModel>();
            Mapper.CreateMap<Page, PageListModel>()
                .ForMember(x =>x.IsRoot, o => o.MapFrom(x => (x.SiteInfo.Root == x)));
            Mapper.CreateMap<Page, PageSimpleModel>();

            Mapper.CreateMap<PageCreateInput, Page>()
                .ForMember(x =>x .Status, o => o.MapFrom(x => Enumeration.FromValue<WorkflowStatus>(x.Status)))
                .ForMember(x => x.PageType, o => o.MapFrom(x => Enumeration.FromDisplayName<PageType>(x.PageType)));
            Mapper.CreateMap<Page, PageCreateInput>();

            Mapper.CreateMap<Page, PageEditInput>()
                .ForMember(x => x.Status, o => o.MapFrom(x => x.Status.Value));
            Mapper.CreateMap<PageEditInput, Page>()
                .ForMember(x => x.PageType, o => o.MapFrom(x => Enumeration.FromDisplayName<PageType>(x.PageType)))
                .ForMember(x => x.Status, o => o.MapFrom(x => Enumeration.FromValue<WorkflowStatus>(x.Status)));

            Mapper.CreateMap<PageQueryInput, PageQuery>()
               .ConstructUsing(x => PageQuery.Default);
            
            // Templates
            Mapper.CreateMap<PageTemplate, TemplateModel>();
            Mapper.CreateMap<PageTemplate, TemplateSimpleModel>();
        }
    }
}