using khmereid_backend.Dtos; using Microsoft.Extensions.Logging; namespace khmereid_backend.Integrations; public class MockAuthnApi : IAuthnApi { private readonly ILogger _logger; private static readonly Guid StaticIdentityId = Guid.Parse("c9ac4dab-cb86-4e5b-8a59-8ecf6a5479a2"); private const string StaticOtp = "000000"; private const string StaticToken = "ory_st_gCk1btBYn0RUCdLV31N60jZlzLgcAoS8"; public MockAuthnApi(ILogger logger) { _logger = logger; } // --------------------------- Registration Flows --------------------------- public Task CreateOtpRegistrationFlowAsync(string phone) { _logger.LogInformation("[Mock] Created registration flow for {Phone}, OTP={Otp}", phone, StaticOtp); return Task.FromResult(new FlowDto { FlowId = "mock_flow_id", State = "sent_otp", ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(5) }); } public Task CompleteOtpRegistrationFlowAsync(string otp, string phone, string flowId) { if (otp != StaticOtp) { return Task.FromResult(new SignupResultDto { Error = "BadRequest", Message = "Invalid OTP." }); } _logger.LogInformation("[Mock] Completed registration for {Phone}, IdentityId={IdentityId}", phone, StaticIdentityId); return Task.FromResult(new SignupResultDto { IdentityId = StaticIdentityId, AccessToken = StaticToken, ExpiredAt = DateTimeOffset.UtcNow.AddHours(1).UtcDateTime }); } // --------------------------- Login Flows --------------------------- public Task CreateOtpLoginFlowAsync(string phone) { _logger.LogInformation("[Mock] Created login flow for {Phone}, OTP={Otp}", phone, StaticOtp); return Task.FromResult(new FlowDto { FlowId = "mock_login_flow_id", State = "sent_otp", ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(5) }); } public Task CompleteOtpLoginFlowAsync(string flowId, string phone, string otp) { if (otp != StaticOtp) { return Task.FromResult(new LoginResultDto { Error = "BadRequest", Message = "Invalid OTP." }); } _logger.LogInformation("[Mock] Completed login for {Phone}, IdentityId={IdentityId}", phone, StaticIdentityId); return Task.FromResult(new LoginResultDto { IdentityId = StaticIdentityId, AccessToken = StaticToken, ExpiredAt = DateTimeOffset.UtcNow.AddHours(1).UtcDateTime }); } // --------------------------- Session & Logout --------------------------- public Task GetMeAsync(string sessionToken) { return Task.FromResult(new SessionDto { Id = StaticIdentityId.ToString(), ExpiresAt = DateTimeOffset.UtcNow.AddHours(1) }); } public Task Logout(string sessionToken) { _logger.LogInformation("[Mock] Logged out session {Token}", sessionToken); return Task.FromResult(new { Message = "Logged out successfully." }); } }