chore(deps): update asf-ui digest to 6cfb52e
[ArchiSteamFarm.git] / ArchiSteamFarm.OfficialPlugins.SteamTokenDumper / Data / SubmitRequest.cs
blob9089ae1f221cc2e8191f367edc6705a043231ec4
1 // ----------------------------------------------------------------------------------------------
2 // _ _ _ ____ _ _____
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
8 // |
9 // Copyright 2015-2024 Ɓukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
11 // |
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 // |
16 // http://www.apache.org/licenses/LICENSE-2.0
17 // |
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
24 using System;
25 using System.Collections.Generic;
26 using System.Collections.Immutable;
27 using System.Globalization;
28 using System.Text.Json.Serialization;
29 using ArchiSteamFarm.Core;
30 using SteamKit2;
32 namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper.Data;
34 internal sealed class SubmitRequest {
35 private readonly ulong SteamID;
37 #pragma warning disable CA1822 // We can't make it static, STJ doesn't serialize it otherwise
38 [JsonInclude]
39 [JsonPropertyName("guid")]
40 private string Guid => ASF.GlobalDatabase?.Identifier.ToString("N") ?? throw new InvalidOperationException(nameof(ASF.GlobalDatabase.Identifier));
41 #pragma warning restore CA1822 // We can't make it static, STJ doesn't serialize it otherwise
43 [JsonInclude]
44 [JsonPropertyName("steamid")]
45 private string SteamIDText => new SteamID(SteamID).Render();
47 #pragma warning disable CA1822 // We can't make it static, STJ doesn't serialize it otherwise
48 [JsonInclude]
49 [JsonPropertyName("token")]
50 private string Token => SharedInfo.Token;
51 #pragma warning restore CA1822 // We can't make it static, STJ doesn't serialize it otherwise
53 #pragma warning disable CA1822 // We can't make it static, STJ doesn't serialize it otherwise
54 [JsonInclude]
55 [JsonPropertyName("v")]
56 private byte Version => SharedInfo.ApiVersion;
57 #pragma warning restore CA1822 // We can't make it static, STJ doesn't serialize it otherwise
59 [JsonInclude]
60 [JsonPropertyName("apps")]
61 [JsonRequired]
62 private ImmutableDictionary<string, string> Apps { get; init; }
64 [JsonInclude]
65 [JsonPropertyName("depots")]
66 [JsonRequired]
67 private ImmutableDictionary<string, string> Depots { get; init; }
69 [JsonInclude]
70 [JsonPropertyName("subs")]
71 [JsonRequired]
72 private ImmutableDictionary<string, string> Subs { get; init; }
74 internal SubmitRequest(ulong steamID, IReadOnlyCollection<KeyValuePair<uint, ulong>> apps, IReadOnlyCollection<KeyValuePair<uint, ulong>> accessTokens, IReadOnlyCollection<KeyValuePair<uint, string>> depots) {
75 if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
76 throw new ArgumentOutOfRangeException(nameof(steamID));
79 ArgumentNullException.ThrowIfNull(apps);
80 ArgumentNullException.ThrowIfNull(accessTokens);
81 ArgumentNullException.ThrowIfNull(depots);
83 SteamID = steamID;
85 Apps = apps.ToImmutableDictionary(static app => app.Key.ToString(CultureInfo.InvariantCulture), static app => app.Value.ToString(CultureInfo.InvariantCulture));
86 Subs = accessTokens.ToImmutableDictionary(static package => package.Key.ToString(CultureInfo.InvariantCulture), static package => package.Value.ToString(CultureInfo.InvariantCulture));
87 Depots = depots.ToImmutableDictionary(static depot => depot.Key.ToString(CultureInfo.InvariantCulture), static depot => depot.Value);