using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;

namespace Umbraco.Cms.Core.Webhooks.Events;

[WebhookEvent("Document Type Changed")]
public class DocumentTypeChangedWebhookEvent : WebhookEventBase<ContentTypeChangedNotification>
{
    public DocumentTypeChangedWebhookEvent(
        IWebhookFiringService webhookFiringService,
        IWebhookService webHookService,
        IOptionsMonitor<WebhookSettings> webhookSettings,
        IServerRoleAccessor serverRoleAccessor)
        : base(webhookFiringService, webHookService, webhookSettings, serverRoleAccessor)
    {
    }

    public override string Alias => Constants.WebhookEvents.Aliases.DocumentTypeChanged;

    public override object ConvertNotificationToRequestPayload(ContentTypeChangedNotification notification)
        => notification.Changes.Select(contentTypeChange => new
        {
            Id = contentTypeChange.Item.Key,
            ContentTypeChange = contentTypeChange.ChangeTypes,
        });
}
