namespace SoulstormReplayReader.Core.Utils;

public static class TicksFormatter
{
    public static class Pattern
    {
        /// <summary> hours : minutes : seconds . milliseconds </summary>
        public const string Hmsf = @"hh\:mm\:ss\.fff";

        /// <summary> hours : minutes : seconds </summary>
        public const string Hms = @"hh\:mm\:ss";

        /// <summary> minutes : seconds </summary>
        public const string Ms = @"mm\:ss";

        /// <summary> minutes : seconds . milliseconds </summary>
        public const string Msf = @"mm\:ss\.fff";

        /// <summary> minutes : seconds . milliseconds </summary>
        public const string Sf = @"ss\.fff";
    }

    public static string Format(int ticks, string pattern = Pattern.Hmsf) =>
        TimeSpan.FromMilliseconds(ticks * 125).ToString(pattern);

    public static string ShortFormat(int ticks)
    {
        var tickMillis = TimeSpan.FromMilliseconds(ticks * 125);

        var formatPattern = tickMillis switch
        {
            { Hours: 0 } => Pattern.Ms,
            _ => Pattern.Hms
        };

        return tickMillis.ToString(formatPattern);
    }
}