/* **********************************************************************************
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 *
 * This source code is subject to terms and conditions of the Shared Source License
 * for IronPython. A copy of the license can be found in the License.html file
 * at the root of this distribution. If you can not locate the Shared Source License
 * for IronPython, please send an email to ironpy@microsoft.com.
 * By using this source code in any fashion, you are agreeing to be bound by
 * the terms of the Shared Source License for IronPython.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * **********************************************************************************/

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

namespace IronPython.Runtime {
    [PythonType("super")]
    public class Super : IDynamicObject, ICustomAttributes {
        public readonly PythonType __thisclass__;
        public readonly object __self__;

        public Super(PythonType thisclass) : this(thisclass, null) { }
        public Super(PythonType thisclass, object self) {
            this.__thisclass__ = thisclass;
            this.__self__ = self;
        }

        public override string ToString() {
            return string.Format("<super: {0}, {1}>", Ops.StringRepr(__thisclass__), Ops.StringRepr(__self__));
        }        

        #region IDynamicObject Members
        public DynamicType GetDynamicType() {
            return Ops.GetDynamicTypeFromType(typeof(Super));
        }
        #endregion

        #region ICustomAttributes Members

        public bool TryGetAttr(ICallerContext context, SymbolId name, out object value) {
            if (__thisclass__.TryLookupSlotInBases(context, name, out value)) {
                value = Ops.GetDescriptor(value, __self__, this);
                return true;
            }
            return false;
        }

        public void SetAttr(ICallerContext context, SymbolId name, object value) {
            throw new NotImplementedException();
        }

        public void DeleteAttr(ICallerContext context, SymbolId name) {
            throw new NotImplementedException();
        }

        public List GetAttrNames(ICallerContext context) {
            throw new NotImplementedException();
        }

        public IDictionary<object, object> GetAttrDict(ICallerContext context) {
            throw new NotImplementedException();
        }

        #endregion
    }
}
