using Inspectron.Settings;
using Inspectron.Settings.Attributes;
using Lindt.Colorballs.Duo.Utils;
using VisionBuilder.UI.Common;

namespace VisionBuilder.UI.Statistics;

public class VisionBuilderStatisticsSettings: ISettings
{
    public string CameraName { get; }

    public VisionBuilderStatisticsSettings(string cameraName)
    {
        CameraName = cameraName;
    }

    [SettingDescription(
        @"
Specifies directory, in which MaxBad and MaxGood are applied.
"+PathSettingsUtils.INSTUCTIONS
    )]
    [SettingPreview(typeof(VisionBuilderStatisticsSettings), nameof(PathTemplatePreview))]
    public string PathTemplate { get; set; }= Path.Combine("..", "Data", "Statistics", "$SS_MONTH_NUM $SS_YEAR", "$RECIPE_NAME");
    
    public string StartDateColumnName { get; set; } = "Start Date";
    public string StartTimeColumnName { get; set; } = "Start time";
    public string EndDateColumnName { get; set; } = "End Date";
    public string EndTimeColumnName { get; set; } = "End time";
    public string ErrorTimeColumnName { get; set; } = "Error time";
    public string ProductColumnName { get; set; } = "Product";
    public string ErrorColumnName { get; set; } = "Error";
    public string MetadataColumnName { get; set; } = "Meta";

    public virtual void RegisterSettings(InspectronSettings settings)
    {
        settings.RegisterSimple(this,()=>this.PathTemplate,CameraName+"/"+"Statistics",nameof(PathTemplate));
        settings.RegisterSimple(this,()=>this.StartDateColumnName,CameraName+"/"+"Statistics",nameof(StartDateColumnName));
        settings.RegisterSimple(this,()=>this.StartTimeColumnName,CameraName+"/"+"Statistics",nameof(StartTimeColumnName));
        settings.RegisterSimple(this,()=>this.EndDateColumnName,CameraName+"/"+"Statistics",nameof(EndDateColumnName));
        settings.RegisterSimple(this,()=>this.EndTimeColumnName,CameraName+"/"+"Statistics",nameof(EndTimeColumnName));
        settings.RegisterSimple(this,()=>this.ErrorTimeColumnName,CameraName+"/"+"Statistics",nameof(ErrorTimeColumnName));
        settings.RegisterSimple(this,()=>this.ProductColumnName,CameraName+"/"+"Statistics",nameof(ProductColumnName));
        settings.RegisterSimple(this,()=>this.ErrorColumnName,CameraName+"/"+"Statistics",nameof(ErrorColumnName));
        settings.RegisterSimple(this,()=>this.MetadataColumnName,CameraName+"/"+"Statistics",nameof(MetadataColumnName));
    }

    public static string PathTemplatePreview(object template)
    {
        return PathSettingsUtils.ConvertVariables((string)template, DateTime.Now, DateTime.Now, "my recipe",
            "my defect", "my camera");
    }
}