namespace Lindt.Colorballs.Duo.Utils;

public static class PathSettingsUtils
{
    public const string INSTUCTIONS = @"
You can use the following system variables:

$RECIPE_NAME - name of the current recipe
$DEFECT_NAME - name of the current defect(for bad images)
$CAMERA_NAME - name of the camera

$HOUR - hour of the image
$MINUTE - minute of the image
$SECOND - second of the image
$MS - milliseconds of the image

$DAY - day of the image
$MONTH_NUM - number of the month of the image
$MONTH_NAME - name of the month of the image
$YEAR - year of the image

$SS_HOUR - hour of the session start
$SS_MINUTE - minute of the session start
$SS_SECOND - second of the session start

$SS_DAY - day of the session start
$SS_MONTH_NUM - number of the month of the session start
$SS_MONTH_NAME - name of the month of the session start
$SS_YEAR - year of the session start";
    public static string ConvertVariables(
        string text,
        DateTime imageTime,
        DateTime sessionTime,
        string recipeName = "",
        string defectName = "",
        string cameraName = "")
    {
        if (string.IsNullOrEmpty(text))
            return text;

        var replacements = new Dictionary<string, string>
        {
            ["$RECIPE_NAME"] = recipeName,
            ["$DEFECT_NAME"] = defectName,
            ["$CAMERA_NAME"] = cameraName,

            ["$HOUR"] = imageTime.Hour.ToString("D2"),
            ["$MINUTE"] = imageTime.Minute.ToString("D2"),
            ["$SECOND"] = imageTime.Second.ToString("D2"),
            ["$MS"] = imageTime.Millisecond.ToString("D3"),

            ["$DAY"] = imageTime.Day.ToString("D2"),
            ["$MONTH_NUM"] = imageTime.Month.ToString("D2"),
            ["$MONTH_NAME"] = imageTime.ToString("MMMM"),
            ["$YEAR"] = imageTime.Year.ToString(),

            ["$SS_HOUR"] = sessionTime.Hour.ToString("D2"),
            ["$SS_MINUTE"] = sessionTime.Minute.ToString("D2"),
            ["$SS_SECOND"] = sessionTime.Second.ToString("D2"),

            ["$SS_DAY"] = sessionTime.Day.ToString("D2"),
            ["$SS_MONTH_NUM"] = sessionTime.Month.ToString("D2"),
            ["$SS_MONTH_NAME"] = sessionTime.ToString("MMMM"),
            ["$SS_YEAR"] = sessionTime.Year.ToString()
        };

        foreach (var pair in replacements)
        {
            text = text.Replace(pair.Key, pair.Value);
        }

        return text;
    }
}