// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.ComponentModel;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using EpicGames.Horde;
using EpicGames.Serialization;
namespace Jupiter.Implementation;
///
/// Identifier for a build
///
[JsonConverter(typeof(BuildNameJsonConverter))]
[TypeConverter(typeof(BuildNameTypeConverter))]
[CbConverter(typeof(BuildNameCbConverter))]
public readonly struct BuildName : IEquatable
{
///
/// The text representing this id
///
readonly StringId _inner;
///
/// Constructor
///
/// Unique id for the string
public BuildName(string input)
{
_inner = new StringId(input);
}
///
public override bool Equals(object? obj) => obj is BuildName id && _inner.Equals(id._inner);
///
public override int GetHashCode() => _inner.GetHashCode();
///
public bool Equals(BuildName other) => _inner.Equals(other._inner);
///
public override string ToString() => _inner.ToString();
///
public static bool operator ==(BuildName left, BuildName right) => left._inner == right._inner;
///
public static bool operator !=(BuildName left, BuildName right) => left._inner != right._inner;
}
///
/// Type converter for BucketId to and from JSON
///
sealed class BuildNameJsonConverter : JsonConverter
{
///
public override BuildName Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => new BuildName(reader.GetString() ?? string.Empty);
///
public override void Write(Utf8JsonWriter writer, BuildName value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString());
}
///
/// Type converter from strings to BucketId objects
///
sealed class BuildNameTypeConverter : TypeConverter
{
///
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type? sourceType) => sourceType == typeof(string);
///
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value) => new BuildName((string)value!);
}
sealed class BuildNameCbConverter : CbConverter
{
public override BuildName Read(CbField field) => new BuildName(field.AsString());
///
public override void Write(CbWriter writer, BuildName value) => writer.WriteStringValue(value.ToString());
///
public override void WriteNamed(CbWriter writer, CbFieldName name, BuildName value) => writer.WriteString(name, value.ToString());
}