using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Interface.IntegryApi;

namespace salesbook.Shared.Core.Services;

public class IntegryNotificationRestClient(
    IUserSession userSession,
    IIntegryApiRestClient integryApiRestClient) : IIntegryNotificationRestClient
{
    public Task<List<WtbNotification>?> Get()
    {
        var queryParams = new Dictionary<string, object>
        {
            { "mode", "ENABLED" },
            { "forUser", userSession.User.Username }
        };

        return integryApiRestClient.Get<List<WtbNotification>>("notification", queryParams);
    }

    public Task<WtbNotification> MarkAsRead(long id) =>
        integryApiRestClient.Post<WtbNotification>("notification/read",
            new ReadNotificationRequestDTO { NotificationId = id, Username = userSession.User.Username })!;

    public Task Delete(long id) =>
        integryApiRestClient.Delete<object>($"notification/{id}", null);

    public Task DeleteAll() =>
        integryApiRestClient.Delete<object>($"notification/all/{userSession.User.Username}", null);
}