using System;
using System.Threading.Tasks;
using Jellyfin.Plugin.Simkl.API.Objects;
using Jellyfin.Plugin.Simkl.API.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Plugin.Simkl.API
{
///
/// The simkl endpoints.
///
[ApiController]
[Authorize(Policy = "DefaultAuthorization")]
[Route("Simkl")]
public class Endpoints : ControllerBase
{
private readonly SimklApi _simklApi;
///
/// Initializes a new instance of the class.
///
/// Instance of the .
public Endpoints(SimklApi simklApi)
{
_simklApi = simklApi;
}
///
/// Gets the oauth pin.
///
/// The oauth pin.
[HttpGet("oauth/pin")]
public async Task> GetPin()
{
return await _simklApi.GetCode();
}
///
/// Gets the status for the code.
///
/// The user auth code.
/// The code status response.
[HttpGet("oauth/pin/{userCode}")]
public async Task> GetPinStatus([FromRoute] string userCode)
{
return await _simklApi.GetCodeStatus(userCode);
}
///
/// Gets the settings for the user.
///
/// The user id.
/// The user settings.
[HttpGet("users/settings/{userId}")]
public async Task> GetUserSettings([FromRoute] Guid userId)
{
var userConfiguration = SimklPlugin.Instance?.Configuration.GetByGuid(userId);
if (userConfiguration == null)
{
return NotFound();
}
return await _simklApi.GetUserSettings(userConfiguration.UserToken);
}
}
}