using System;
using System.Collections.Generic;
using System.Data;
using Aitex.Core.RT.DBCore;
using SciChart.Core.Extensions;

namespace Aitex.Core.RT.DataCollection.HighPerformance;

public class DataTraceHelper
{
    public static readonly IEnumerable<Type> SupportedValueTypes =
    [
        typeof(bool), typeof(double), typeof(float), typeof(int), typeof(uint),
        typeof(short), typeof(ushort), typeof(long), typeof(ulong)
    ];
    
    public static string Format<T>(T value)
    {
        if (value is bool b)
            return b ? "'1'" : "'0'";
        
        if (value is float or double)
        {
            var dVal = Convert.ToDouble(value);
            return dVal.IsNaN() ? "'0.0'" : $"'{value}'";
        }

        if (value is int or uint or ushort or short or ulong or long)
        {
            return  $"'{value}'";
        }

        throw new InvalidCastException("unknown type of data to be cached.");
    }

    public static DataTable CheckDiskUsage()
    {
        var sql = MECF.Framework.Common.Properties.Resources.SqlScript_TableDiskUsage;
        return DB.ExecuteDataTable(sql);
    }
}