using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace FormulaEditor
{
    public class ArraySingleOperation : IObjectOperation
    {
        private object returnType;
        private ArraySingleOperationType operationType;

        public ArraySingleOperation(ArraySingleOperationType operationType, object type)
        {
            this.operationType = operationType;
            ArrayReturnType art = type as ArrayReturnType;
            object t = art.ElementType;
            if (t is Double)
            {
                Double a = 0;
                returnType = a;
            }
        }
        #region IObjectOperation Members

        public int Arity
        {
            get
            {
                return 1;
            }
        }

        public object this[object[] x]
        {
            get
            {
                double a = 0;
                object[] y = x[0] as object[];
                if (operationType == ArraySingleOperationType.Sum)
                {
                    for (int i = 0; i < y.Length; i++)
                    {
                        a += (double)y[i];
                    }
                    return a;
                }
                return null;
            }
        }

        public object ReturnType
        {
            get
            {
                return returnType;
            }
        }

        public bool IsPowered
        {
            get
            {
                return false;
            }
        }

        #endregion
    }

    public enum ArraySingleOperationType
    {
        Sum, Product
    }

}
