// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Diagnostics.CodeAnalysis;
namespace EpicGames.Horde.Jobs
{
///
/// Unique id struct for JobStepRef objects. Includes a job id, batch id, and step id to uniquely identify the step.
///
public struct JobStepRefId : IEquatable, IComparable
{
///
/// The job id
///
public JobId JobId { get; set; }
///
/// The batch id within the job
///
public JobStepBatchId BatchId { get; set; }
///
/// The step id
///
public JobStepId StepId { get; set; }
///
/// Constructor
///
/// The job id
/// The batch id within the job
/// The step id
public JobStepRefId(JobId jobId, JobStepBatchId batchId, JobStepId stepId)
{
JobId = jobId;
BatchId = batchId;
StepId = stepId;
}
///
/// Parse a job step id from a string
///
/// Text to parse
/// The parsed id
public static JobStepRefId Parse(string text)
{
string[] components = text.Split(':');
return new JobStepRefId(JobId.Parse(components[0]), JobStepBatchId.Parse(components[1]), JobStepId.Parse(components[2]));
}
///
/// Formats this id as a string
///
/// Formatted id
public override string ToString()
{
return $"{JobId}:{BatchId}:{StepId}";
}
///
public override int GetHashCode() => HashCode.Combine(JobId, BatchId, StepId);
///
public override bool Equals([NotNullWhen(true)] object? obj) => obj is JobStepRefId other && Equals(other);
///
public bool Equals(JobStepRefId other)
{
return JobId.Equals(other.JobId) && BatchId.Equals(other.BatchId) && StepId.Equals(other.StepId);
}
///
public int CompareTo(JobStepRefId other)
{
int result = JobId.Id.CompareTo(other.JobId.Id);
if (result != 0)
{
return result;
}
result = BatchId.SubResourceId.Value.CompareTo(other.BatchId.SubResourceId.Value);
if (result != 0)
{
return result;
}
return StepId.Id.Value.CompareTo(other.StepId.Id.Value);
}
///
public static bool operator ==(JobStepRefId lhs, JobStepRefId rhs) => lhs.Equals(rhs);
///
public static bool operator !=(JobStepRefId lhs, JobStepRefId rhs) => !lhs.Equals(rhs);
///
public static bool operator <(JobStepRefId lhs, JobStepRefId rhs) => lhs.CompareTo(rhs) < 0;
///
public static bool operator >(JobStepRefId lhs, JobStepRefId rhs) => lhs.CompareTo(rhs) > 0;
///
public static bool operator <=(JobStepRefId lhs, JobStepRefId rhs) => lhs.CompareTo(rhs) <= 0;
///
public static bool operator >=(JobStepRefId lhs, JobStepRefId rhs) => lhs.CompareTo(rhs) >= 0;
}
}