using Leanetec.EConnect.Domain.Entities;
using MediatR;

namespace Leanetec.EConnect.Client.Articles;

/// <summary>
/// Extension methods for the <see cref="IMediator"/> interface to simplify working with <see cref="Article"/> entities.
/// </summary>
public static class PutExtensions
{
    /// <summary>
    /// Sends a request to update an existing <see cref="Article"/> using MediatR.
    /// </summary>
    /// <param name="mediator">The <see cref="IMediator"/> instance used to send the request.</param>
    /// <param name="article">The <see cref="Article"/> entity to be updated.</param>
    /// <param name="apiVersion">Optional API version to include in the request.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public static Task UpdateArticleAsync(this IMediator mediator, Article article, int? apiVersion = null) => mediator.Send(new PutRequest(article)
    {
        ApiVersion = apiVersion
    });

    /// <summary>
    /// Sends a request to update an existing <see cref="Article"/> using MediatR.
    /// </summary>
    /// <param name="mediator">The <see cref="IMediator"/> instance used to send the request.</param>
    /// <param name="article">The <see cref="Article"/> entity to be updated.</param>
    /// <param name="apiVersion">Optional API version to include in the request.</param>
    public static void UpdateArticle(this IMediator mediator, Article article, int? apiVersion = null) => mediator.Send(new PutRequest(article)
    {
        ApiVersion = apiVersion
    }).GetAwaiter().GetResult();
}
