﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace VDG
{
    public partial class GammaRuntime
    {
        public class GammaList
        {
            private Int32 cursor;
            private List<object> list = new List<object>();

            public GammaList()
            {
                this.cursor = 0;
            }

            public GammaList(object[] array)
            {
                this.list = array.ToList();
                this.cursor = 0;
            }

            public GammaList(List<object> array)
            {
                this.list = array;
                this.cursor = 0;
            }

            public virtual void Add(object var)
            {
                list.Add(var);
            }

            public virtual List<object> BaseList()
            {
                return list;
            }

            public virtual void Clear()
            {
                list.Clear();
            }

            public virtual Boolean Contains(object value)
            {
                return list.Contains(value);
            }

            public virtual Int64 Count()
            {
                return list.Count();
            }

            public virtual object Current()
            {
                if (this.list.Count <= this.cursor) return false;
                return this.list.ElementAt(this.cursor);
            }

            public virtual object GetElementAt(Int64 index)
            {
                return list.ElementAt(Convert.ToInt32(index));
            }

            public virtual void Insert(Int64 index, object var)
            {
                list.Insert(Convert.ToInt32(index), var);
            }

            public virtual object Next()
            {
                if (this.list.Count <= this.cursor) return false;
                return this.list.ElementAt(this.cursor++);
            }

            public virtual object Previous()
            {
                if (this.cursor <= 0) return false;
                return this.list.ElementAt(--this.cursor);
            }

            public virtual void Remove(Int32 index)
            {
                list.RemoveAt(index);
            }

            public virtual void RemoveAll(object search)
            {
                list.RemoveAll(a => a == search);
            }

            public virtual void Seek()
            {
                this.cursor = 0;
            }

            public virtual void Seek(Int32 i)
            {
                if (i < 0 || this.list.Count <= i) throw new FatalException("(.Seek) Undefined index " + i.ToString() + " in list");
                this.cursor = i;
            }

            public virtual void SetElementAt(Int64 index, object var)
            {
                list[Convert.ToInt32(index)] = (var);
            }
        }
    }
}