﻿using Composite.Core.Application;
using Composite.Core.Routing;
using Composite.Data;
using System;
using System.Linq;

namespace Composite.Demo
{
    [ApplicationStartup]
    public static class StartupHandler
    {
        // The ID of the page to show the data of the Demo.News type on - change accordingly
        static readonly Guid TargetPageId = new Guid("055a1076-099b-420c-a9cc-f591e0819782"); 
        
        public static void OnBeforeInitialize()
        {

        }

        public static void OnInitialized()
        {
            // Finding a dynamic data type
            var dataType = DataFacade.GetAllInterfaces().FirstOrDefault(u => u.Name == "News");

            // var dataType = typeof(....);
            if (dataType != null)
            {
                DataUrls.RegisterGlobalDataUrlMapper(dataType, new NewsDataMapper(dataType, TargetPageId));
            }
        }

    }
}
