using System;
using System.Collections.Generic;

namespace InABox.Core
{
    // need to add a property to signaturefield (manager signature or something) that prevents a form being saved for later if the 
    // manager signature is present - ensures that form is completed and submitted / cannot be changed
    public class DFLayoutSignaturePadProperties : DFLayoutFieldProperties<byte[]>
    {
        public override string FormatValue(object value)
        {
            return value != null ? "Yes" : "";
        }

        public override object? ParseValue(object value)
        {
            if (value is byte[])
                return value;

            if (value is string str)
            {
                if (Guid.TryParse(str, out var id))
                {
                    return Array.Empty<byte>();
                }
                try
                {
                    return Convert.FromBase64String(str);
                }
                catch (Exception e)
                {
                    return null;
                }
            }

            return null;
        }
    }
}