using Lucene.Net.Tartarus.Snowball;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.Share.Tools;

public static class DoubleExtensions
{
    /// <summary>
    /// 秒数转换成 x天x小时x分钟x秒 的字符串
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static string SecondsToString(this double value)
    { 
        if (value <= 0) return string.Empty;

        var timeSpan = TimeSpan.FromSeconds(value);
        var days = timeSpan.Days;
        var hours = timeSpan.Hours;
        var minutes = timeSpan.Minutes;
        var seconds = timeSpan.Seconds;

        var sb = new StringBuilder();
        if (days > 0)
        {
            sb.Append($"{days}天");
        }
        if (hours > 0 || days > 0)
        {
            sb.Append($"{hours}小时");
        }
        if (hours > 0 || days > 0 || minutes > 0)
        {
            sb.Append($"{minutes}分钟");
        }
        sb.Append($"{seconds}秒");
        return sb.ToString();
    }

    public static string SecondsToString(this double? value)
    {
        if (value is null) return string.Empty;

        return value.Value.SecondsToString();
    }

    public static string ToYuanFinance(this double value)
    {
        return value.ToString("F2");
    }
}
