using System;

namespace InABox.Core
{
    public class DFLayoutDocumentFieldProperties : DFLayoutFieldProperties<Guid>
    {
        public string? FileMask { get; set; }

        public override string FormatValue(object? value)
        {
            return value != null ? "Yes" : "";
        }

        public override object? ParseValue(object? value)
        {
            if (value is Guid)
                return value;

            if (value is string)
                try
                {
                    return Guid.Parse(value as string);
                }
                catch (Exception)
                {
                    return null;
                }

            return null;
        }

        protected override void LoadProperties()
        {
            base.LoadProperties();
            FileMask = GetProperty("FileMask", FileMask);
        }

        protected override void SaveProperties()
        {
            base.SaveProperties();
            SetProperty("FileMask", FileMask);
        }
    }
}