using System;

using BeWo.Office.Types;

namespace BeWo.Office.TableModels
{
    public abstract class AbstractTableModel : ITableModel
    {
        private String[] _FieldNames;
        public virtual int Count { get; private set; }
        public abstract bool DataAvailable { get; }
        public string[] GetFieldNames()
        {
            return _FieldNames ?? (_FieldNames = CreateFieldNames());
        }

        public string[] GetVariableNames()
        {
            return GetFieldNames();
        }

        protected string CleanFieldName(string name)
        {
            String fieldName = name.TrimStart(' ').TrimEnd(' ')
                .Replace(" ", "_")
                .Replace(".", "")
                .Replace("!", "")
                .Replace("?", "")
                .Replace(":", "")
                .Replace("(", "")
                .Replace(")", "")
                .Replace("/", "")
                .Replace("-", "")
                .Replace("+", "")
                .Replace("&", "");
            if (fieldName.Length > 40)
                fieldName = fieldName.Substring(0, 40); //HACK: Wordserienbrieffelder dürfen max.40 Zeichen lang sein. Weiss gerade noch nicht, wo das richtigerweise gemacht werden soll
            return fieldName;
        }

        public abstract object GetPropertyValue(string propertyName);

        protected abstract string[] CreateFieldNames();

        public abstract void MoveFirst();

        public abstract void MoveLast();

        public abstract void MoveNext();

        public abstract void MovePrevious();
    }
}
