using LinqToDB;
using MediaManager.database;
using MediaManager.database.Tables;

namespace MediaManager; 

public static class AuthUtil {
	public static string GetRemoteUser(HttpContext ctx, Database.DbConn db) {
		#if (DEBUG)
		const string remoteUser = "debuguser";
		#else
		var remoteUser = ctx.Request.Headers["Remote-User"];
		#endif

		if (!db.Users.Any(p => p.Username == remoteUser)) {
			db.InsertWithInt32Identity(new User {Username = remoteUser});
		}
		return remoteUser;
	}
}
