// Copyright (C) 2015-2026 The Neo Project.
//
// Helper.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.SmartContract.Manifest;

namespace Neo.CLI;

internal static class Helper
{
    public static bool IsYes(this string input)
    {
        if (input == null) return false;

        input = input.ToLowerInvariant();

        return input == "yes" || input == "y";
    }

    public static string ToBase64String(this byte[] input) => Convert.ToBase64String(input);

    public static void IsScriptValid(this ReadOnlyMemory<byte> script, ContractAbi abi)
    {
        try
        {
            SmartContract.Helper.Check(script.ToArray(), abi);
        }
        catch (Exception e)
        {
            throw new FormatException($"Contract script validation failed. The provided script or manifest format is invalid and cannot be processed. Please verify the script bytecode and manifest are correctly formatted and compatible. Original error: {e.Message}", e);
        }
    }
}
