namespace Quadarax.Foundation.Core.Value.Formatters
{
    /// <summary>
    /// Formatter for forms of seconds/hours/day
    /// </summary>
    public class HmsFormatter : ICustomFormatter, IFormatProvider 
    {
        static Dictionary<string, string> _timeformats = new()
        {
            {"S", "{0:P:Seconds:Second}"},
            {"M", "{0:P:Minutes:Minute}"},
            {"H","{0:P:Hours:Hour}"},
            {"D", "{0:P:Days:Day}"}
        };

        public string Format(string? format, object? arg, IFormatProvider? formatProvider)
        {
            return string.Format(new PluralFormatter(),format == null ? string.Empty : _timeformats[format], arg);
        }

        public object? GetFormat(Type? formatType)
        {
            return formatType == typeof(ICustomFormatter)?this:null;
        }
    }
}
