using FileSplitter.Shared.Enums;

using Newtonsoft.Json;

namespace FileSplitter.Shared.Classes;

public static class Localization
{
    //Содержимое языкового файла
    private static readonly FileSplitterLanguage Language;

    /// <summary>
    /// Конструктор
    /// </summary>
    static Localization()
    {
        //Создаю опции приложения
        FileSplitterConsoleOptions options = new();
        //- и загружаю их
        options.Load();

        //Язык приложения
        string language = options.Language;

        //Если файла языка не существует
        if (!File.Exists($"languages\\{language}.json"))
            //- то используем русский
            language = "russian";

        //Читаю файл
        string languageContent = File.ReadAllText($"languages\\{language}.json");

        //Загружаю парсер
        Language = JsonConvert.DeserializeObject<FileSplitterLanguage>(languageContent) ?? new ();

        //Задаю массивы
        //- размеров файлов
        FileSizeStrings = new[]
        {
            Language.FileSizeStringsByte,
            Language.FileSizeStringsKByte,
            Language.FileSizeStringsMByte,
            Language.FileSizeStringsGByte,
            Language.FileSizeStringsTByte
        };

        //- кодов ответов
        ExitCodeNames = new()
        {
            (FsExitCode.ecAllDone, Language.ExitCodeNamesAllDone),
            (FsExitCode.ecInvalidParameters, Language.ExitCodeNamesInvalidParameters),
            (FsExitCode.ecUserAborted, Language.ExitCodeNamesUserAborted),
            (FsExitCode.ecUnknownInfoFile, Language.ExitCodeNamesUnknownInfoFile),
            (FsExitCode.ecInfoVersionUnsupported, Language.ExitCodeNamesInfoVersionUnsupported),
            (FsExitCode.ecSplitFileHashError, Language.ExitCodeNamesSplitFileHashError),
            (FsExitCode.ecTargetFileCheckError, Language.ExitCodeNamesTargetFileCheckError)
        };
    }

    //Параметры приложения
    public static string AppTitle => Language.AppTitle;
    public static string AppVersion => Language.AppVersion;
    public static string AppCopyrights => Language.AppCopyrights;

    //Сообщения
    public static string MessageNoParametersForSplit => Language.MessageNoParametersForSplit;
    public static string MessageSplitAsk => Language.MessageSplitAsk;
    public static string MessageStartSplit => Language.MessageStartSplit;
    public static string MessageSplitFilePart => Language.MessageSplitFilePart;
    public static string MessageSplitComplete => Language.MessageSplitComplete;
    public static string MessageHashCheckStart => Language.MessageHashCheckStart;
    public static string MessageHashCheckFail => Language.MessageHashCheckFail;
    public static string MessageHashCheckComplete => Language.MessageHashCheckComplete;
    public static string MessageJoinAsk => Language.MessageJoinAsk;
    public static string MessageStartJoin => Language.MessageStartJoin;
    public static string MessageJoinUnsupportedFile => Language.MessageJoinUnsupportedFile;
    public static string MessageJoinUnknownFile => Language.MessageJoinUnknownFile;
    public static string MessageJoinHashError => Language.MessageJoinHashError;
    public static string MessageJoinCheckError => Language.MessageJoinCheckError;
    public static string MessageJoinFilePart => Language.MessageJoinFilePart;
    public static string MessageJoinComplete => Language.MessageJoinComplete;
    public static string MessagePleaseWaitToReady => Language.MessagePleaseWaitToReady;

    //Сообщения интерактивного режима
    public static string InteractiveStartAsk => Language.InteractiveStartAsk;
    public static string InteractiveWrongInput => Language.InteractiveWrongInput;
    public static string InteractiveOperationFinish => Language.InteractiveOperationFinish;
    public static string InteractiveFileNameNotExist => Language.InteractiveFileNameNotExist;
    public static string InteractiveFileNameExist => Language.InteractiveFileNameExist;

    public static string InteractiveSplitFileNameAsk => Language.InteractiveSplitFileNameAsk;
    public static string InteractiveSplitFileNameResult => Language.InteractiveSplitFileNameResult;
    public static string InteractiveSplitTargetDirAsk => Language.InteractiveSplitTargetDirAsk;
    public static string InteractiveSplitTargetDirResult => Language.InteractiveSplitTargetDirResult;
    public static string InteractiveSplitPartSizeAsk => Language.InteractiveSplitPartSizeAsk;
    public static string InteractiveSplitPartSizeAsk2 => Language.InteractiveSplitPartSizeAsk2;
    public static string InteractiveSplitPartSizeResult => Language.InteractiveSplitPartSizeResult;
    public static string InteractiveSplitOptionsAsk => Language.InteractiveSplitOptionsAsk;
    public static string InteractiveSplitOptionsResult => Language.InteractiveSplitOptionsResult;

    public static string InteractiveJoinFileNameAsk => Language.InteractiveJoinFileNameAsk;
    public static string InteractiveJoinFileNameResult => Language.InteractiveJoinFileNameResult;
    public static string InteractiveJoinTargetFileNameAsk => Language.InteractiveJoinTargetFileNameAsk;
    public static string InteractiveJoinTargetFileNameResult => Language.InteractiveJoinTargetFileNameResult;
    public static string InteractiveJoinOptionsAsk => Language.InteractiveJoinOptionsAsk;
    public static string InteractiveJoinOptionsResult => Language.InteractiveJoinOptionsResult;

    public static string InteractiveOptionsAsk => Language.InteractiveOptionsAsk;
    public static string InteractiveOptionsConfirm => Language.InteractiveOptionsConfirm;
    public static string InteractiveOptionsResult => Language.InteractiveOptionsResult;

    //Константы размеров
    public static string[] FileSizeStrings { get; }

    //Переводы кодов возврата
    public static List<(FsExitCode, string)> ExitCodeNames { get; }
}