using System;

namespace Sonex.Client.Data
{
    public abstract class DataColumnBase
    {
        public string Key { get; }
        public string Header { get; set; }
        public string? ValueFormat { get; set; }

        public abstract Type DataType { get; }
        public abstract int RowCount { get; }

        protected DataColumnBase(string key, string header)
        {
            ArgumentException.ThrowIfNullOrWhiteSpace(key);
            ArgumentException.ThrowIfNullOrWhiteSpace(header);

            Key = key;
            Header = header;
        }

        public virtual string? GetValue(int rowIndex)
        {
            ValidateRowIndex(rowIndex);
            return FormatValue(rowIndex);
        }

        public abstract void SetValue(int rowIndex, string? value);

        public abstract object? GetRawValue(int rowIndex);
        public abstract void SetRawValue(int rowIndex, object? value);

        public abstract void AddEmpty();

        protected abstract string? FormatValue(int rowIndex);

        protected void ValidateRowIndex(int rowIndex)
        {
            if (rowIndex < 0 || rowIndex >= RowCount)
                throw new ArgumentOutOfRangeException(nameof(rowIndex));
        }
    }
}