//
//  ParameterInfoExtensions.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using NosSmooth.PacketSerializersGenerator.Data;
using NosSmooth.PacketSerializersGenerator.Errors;
namespace NosSmooth.PacketSerializersGenerator.Extensions;
/// 
/// Extensions for .
/// 
public static class ParameterInfoExtensions
{
    /// 
    /// Gets the name of the error variable.
    /// 
    /// The parameter.
    /// The name of the error variable.
    public static string GetErrorVariableName(this ParameterInfo parameterInfo)
    {
        return $"{parameterInfo.Name}Error";
    }
    /// 
    /// Gets the name of the error variable.
    /// 
    /// The parameter.
    /// The name of the error variable.
    public static string GetResultVariableName(this ParameterInfo parameterInfo)
    {
        return $"{parameterInfo.Name}Result";
    }
    /// 
    /// Gets the name of the token variable.
    /// 
    /// The parameter.
    /// The name of the token variable.
    public static string GetTokenVariableName(this ParameterInfo parameterInfo)
    {
        return $"{parameterInfo.Name}Token";
    }
    /// 
    /// Gets the name of the error variable.
    /// 
    /// The parameter.
    /// The name of the error variable.
    public static string GetVariableName(this ParameterInfo parameterInfo)
    {
        return parameterInfo.Name;
    }
    /// 
    /// Gets the name of the nullable variable.
    /// 
    /// The parameter.
    /// The name of the nullable variable.
    public static string GetNullableVariableName(this ParameterInfo parameterInfo)
    {
        return $"{parameterInfo.Name}Nullable";
    }
    /// 
    /// Gets the type of the parameter as nullable.
    /// 
    /// The parameter.
    /// The nullable type.
    public static string GetNullableType(this ParameterInfo parameterInfo)
    {
        return parameterInfo.Type.ToString().TrimEnd('?') + "?";
    }
    /// 
    /// Gets the type of the parameter with ? if the parameter is nullable..
    /// 
    /// The parameter.
    /// The type.
    public static string GetActualType(this ParameterInfo parameterInfo)
    {
        return parameterInfo.Type.ToString().TrimEnd('?') + (parameterInfo.Nullable ? "?" : string.Empty);
    }
    /// 
    /// Gets whether the parameter is marked as optional.
    /// 
    /// The parameter info.
    /// Whether the parameter is optional.
    public static bool IsOptional(this ParameterInfo parameterInfo)
    {
        return parameterInfo.Attributes.First().GetNamedValue("IsOptional", false);
    }
}