namespace MiGu.Server.Configs;

public record WidgetGrantDto(string WidgetId, string Visibility);

public record AuthRole(
    string Id, string Name, string Scope,
    List<string> Permissions,
    List<WidgetGrantDto> WidgetGrants);

public record AuthUser(string Id, string Username, List<string> Roles, bool Enabled);

public record AuthRoleConfig(List<AuthRole> Roles, List<AuthUser> Users)
{
    public static AuthRoleConfig Default() => new(
        Roles: new List<AuthRole>
        {
            new("role-admin", "管理员", "Platform",
                new List<string> { "*" },
                new List<WidgetGrantDto>()),
            new("role-ops", "运营", "RCSMonitor",
                new List<string>
                {
                    "ops.car.pause", "ops.car.resume", "ops.car.gohome",
                    "ops.task.pause", "ops.task.cancel", "ops.task.reassign",
                    "ops.task.boostPriority", "monitor.note.write"
                },
                new List<WidgetGrantDto>
                {
                    new("MapEditor", "readonly"),
                    new("CadToolbar", "hidden")
                })
        },
        Users: new List<AuthUser>
        {
            new("u-admin", "admin", new List<string> { "role-admin" }, true),
            new("u-ops", "ops", new List<string> { "role-ops" }, true)
        });
}

public record EffectivePermissions(
    string UserId,
    int Version,
    List<string> AllowedOps,
    List<WidgetGrantDto> VisibleWidgets,
    List<string> AllowedPages);
