﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypedDataGrid.Validators;

namespace TypedDataGrid.Settings.Attributes.Validators
{
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public class StringByteLengthValueValidatorAttribute : ValueValidatorAttribute
    {
        public StringByteLengthValueValidatorAttribute(int max)
        {
            this.Max = max;
            this.EncodingCodePage = Encoding.UTF8.CodePage;
        }


        public int Min { get; set; }

        public int Max { get; set; }

        public int EncodingCodePage { get; set; }


        public override IValueValidator CreateInstance()
        {
            return new StringByteLengthValueValidator(this.Min, this.Max, Encoding.GetEncoding(this.EncodingCodePage));
        }
    }
}
