namespace InABox.Core
{
    public class DFLayoutPINFieldProperties : DFLayoutFieldProperties<string>
    {
        public int Length { get; set; }

        public DFLayoutPINFieldProperties()
        {
            Length = 4;
        }

        public override string FormatValue(object value)
        {
            return value?.ToString() ?? "";
        }

        public override object? ParseValue(object value)
        {
            if (value is int)
                return value.ToString();
            if (value is string) return value;
            return null;
        }

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

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