// using Modules.User.Application.Gateways; // using Modules.User.Application.Models; // using Modules.User.Application.Models.Access; // using Modules.User.Database.Repositories; // using ClientInfo = Modules.User.Application.Models.ClientInfo; // using Session = Modules.User.Application.Models.Session; // // namespace Modules.User.Database.GatewaysImplementations; // // public class AccountGateway(SessionRepository sessionRepository, RoleRepository roleRepository) : IAccountGateway // { // public async Task> GetAccountSessions(Guid accountId) // { // var sessions = await sessionRepository.GetAll(accountId); // return sessions.Select(q => new Session // { // Id = q.Id, // RefreshToken = q.RefreshToken, // ClientInfo = new ClientInfo // { // UserAgent = q.ClientInfo.UserAgent, // Location = new Location // { // Country = q.ClientInfo.Country, // Region = q.ClientInfo.Region, // }, // }, // LastOnline = q.LastUpdate, // AccountId = q.AccountId, // ExpiredDate = q.ExpiredDate, // }).ToList(); // } // // public async Task TryGetSession(string refreshToken) // { // var session = await sessionRepository.GetFirstOrDefaultWhere(q => q.RefreshToken == refreshToken.Trim() // && q.ExpiredDate > DateTime.UtcNow); // return session == null ? null : new Session // { // Id = session.Id, // RefreshToken = session.RefreshToken, // ClientInfo = new() // { // UserAgent = session.ClientInfo.UserAgent, // Location = new() // { // Country = session.ClientInfo.Country, // Region = session.ClientInfo.Region, // }, // }, // AccountId = session.AccountId, // ExpiredDate = session.ExpiredDate, // }; // } // // public async Task UpdateSessions(Guid accountId, IEnumerable sessions, IEnumerable? forceUpdateSessionIds = null) // { // return await sessionRepository.SyncSessions(accountId, sessions.Select(q => new Database.Entities.Session // { // Id = q.Id != Guid.Empty ? q.Id : Guid.NewGuid(), // RefreshToken = q.RefreshToken, // ClientInfo = new() // { // UserAgent = q.ClientInfo.UserAgent, // Country = q.ClientInfo.Location.Country, // Region = q.ClientInfo.Location.Region, // }, // AccountId = q.AccountId, // ExpiredDate = q.ExpiredDate, // }).ToList(), forceUpdateSessionIds?.ToList()); // } // // public async Task> GetAccountRoles(Guid accountId) // { // var accountRoles = await roleRepository.GetAccountRoles(accountId, true); // // return accountRoles.Select(q => new Role // { // Id = q.Id, // Permissions = [..q.Permissions.Select(x => new Permission // { // Id = x.Id, // Name = x.Name, // Code = x.Code, // })], // Name = q.Name // }); // } // // public async Task> GetAccountPermissions(Guid accountId) // { // var accountPermissions = await roleRepository.GetAccountPermissions(accountId); // // return accountPermissions.Select(q => new Permission // { // Id = q.Id, // Name = q.Name, // Code = q.Code, // }); // } // }