summary refs log tree commit diff
path: root/extra/admin-api/Models/Spacebar.Models.Generic/Member.cs
blob: bb01fc47de13ec6515956109ceac19f755cf84e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace Spacebar.Models.Generic;

[DebuggerDisplay("{User.Id} ({User.Username}#{User.Discriminator})")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
[SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")]
[JsonConverter(typeof(MemberJsonConverter))]
public class Member
{
    [JsonPropertyName("user")]
    public required PartialUser User { get; set; }

    [JsonPropertyName("nick")]
    public string? Nick { get; set; }

    [JsonPropertyName("avatar")]
    public string? Avatar { get; set; }

    [JsonPropertyName("avatar_decoration_data")]
    public JsonObject? AvatarDecorationData { get; set; }

    [JsonPropertyName("collectibles")]
    public JsonObject? Collectibles { get; set; }

    [JsonPropertyName("display_name_styles"), JsonIgnore(Condition = JsonIgnoreCondition.Never)]
    public DisplayNameStyle? DisplayNameStyles { get; set; }

    [JsonPropertyName("banner")]
    public string? Banner { get; set; }

    [JsonPropertyName("bio")]
    public string? Bio { get; set; }

    [JsonPropertyName("roles"), JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)]
    public List<long>? Roles { get; set; }
}

// Unsure if this is used anywhere outside of op14...?
public class MemberWithPresence : Member
{
    [JsonPropertyName("presence")]
    public Presence? Presence { get; set; }
}

public class MemberJsonConverter : JsonConverter<Member>
{
    public override Member? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        throw new NotImplementedException(); // TODO
    }

    public override void Write(Utf8JsonWriter writer, Member value, JsonSerializerOptions options) => JsonSerializer.Serialize(writer, value, value.GetType(), options);
}