using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SVSim.EmulatedEntrypoint.Constants;
using SVSim.EmulatedEntrypoint.Security;
using SVSim.EmulatedEntrypoint.Security.SteamSessionAuthentication;
namespace SVSim.EmulatedEntrypoint.Controllers
{
///
/// A base controller for SVSim with helpers for getting some values.
///
[Route("[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = SteamAuthenticationConstants.SchemeName)]
public abstract class SVSimController : ControllerBase
{
///
/// Reads the authenticated viewer's internal id from the ViewerId claim populated by
/// SteamSessionAuthenticationHandler. Returns false (and viewerId = 0) when the
/// claim is missing or unparseable — handler should respond with Unauthorized().
///
protected bool TryGetViewerId(out long viewerId)
{
viewerId = 0;
var claim = User.Claims.FirstOrDefault(c => c.Type == ShadowverseClaimTypes.ViewerIdClaim)?.Value;
return claim is not null && long.TryParse(claim, out viewerId);
}
}
}