using System;
using System.Net.Http.Headers;
using Quadarax.Foundation.Core.Value;

namespace Quadarax.Foundation.Core.Data;

public class TypedArgument : ITypedArgument
{
    public string Name {get; private set;}
    public string? Value {get; set;}  //TODO: must be nullable
    public Type ValueType {get; private set;}
       
    public bool IsOutput {get; private set;}
       
    public TypedArgument(string name, string? valueAsString, Type? valueType, bool isOutput = false)
    {
        Name = name ?? throw new ArgumentNullException(nameof(name));
        ValueType = valueType ?? throw new ArgumentNullException(nameof(valueType));
        Value = valueAsString;
        IsOutput = isOutput;
    }
    public TypedArgument(string name, Type valueType, bool isOutput = false) : this(name, string.Empty, valueType, isOutput)
    {
         
    }
    public TypedArgument(string name, Type valueType, object? valueTyped, bool isOutput = false) : this(name, valueTyped?.ToString(), valueType, isOutput)
    {
         
    }
    public TypedArgument(string name, object valueTyped, bool isOutput = false) : this(name, valueTyped?.ToString(), valueTyped?.GetType(), isOutput)
    {
         
    }

    public TValue? GetTypedValue<TValue>()
    {
        if (Value == null) return default(TValue);
        return ValueConverter.ConvertTo<TValue>(Value);
    }

}
   