using Jellyfin.Plugin.Simkl.API.Objects;
using Jellyfin.Plugin.Simkl.API.Responses;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
#pragma warning disable CA1801
namespace Jellyfin.Plugin.Simkl.API
{
///
/// Server endpoints.
///
public class ServerEndpoint : IService, IHasResultFactory
{
private readonly SimklApi _api;
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
///
/// Initializes a new instance of the class.
///
/// The simkl api.
/// Instance of the interface.
/// Instance of the interface.
public ServerEndpoint(SimklApi api, ILogger logger, IJsonSerializer json)
{
_api = api;
_logger = logger;
_json = json;
}
///
/// Gets or sets result factory.
///
public IHttpResultFactory ResultFactory { get; set; }
///
/// Gets or sets request.
///
public IRequest Request { get; set; }
///
/// Get pin request.
///
/// The request.
/// The code response.
public CodeResponse Get(GetPin request)
{
return _api.GetCode().GetAwaiter().GetResult();
}
///
/// Get pin status.
///
/// The request.
/// Code status response.
public CodeStatusResponse Get(GetPinStatus request)
{
return _api.GetCodeStatus(request.UserCode).GetAwaiter().GetResult();
}
///
/// Get user settings.
///
/// The request.
/// User settings.
public UserSettings Get(GetUserSettings request)
{
_logger.LogDebug(_json.SerializeToString(request));
return _api.GetUserSettings(SimklPlugin.Instance.Configuration.GetByGuid(request.UserId).UserToken).Result;
}
}
}