// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Elena Vakhtina
// Created:    2008.09.11

using System;

using Xtensive.Orm.Rse;

namespace Xtensive.Orm.Rse
{
  /// <summary>
  /// Descriptor of the calculated column.
  /// </summary>
  [Serializable]
  public class AggregateColumnDescriptor
  {
    private const string ToStringFormat = "{0} = {1} on ({2})";

    /// <summary>
    /// Gets the column index.
    /// </summary>
    public string Name { get; private set; }

    /// <summary>
    /// Gets the column index.
    /// </summary>
    public int SourceIndex { get; private set; }

    /// <summary>
    /// Gets the column type.
    /// </summary>
    public AggregateType AggregateType { get; private set; }

    /// <summary>
    /// Gets hint of decimal's presicion and scale, if such are known.
    /// </summary>
    public (int Precision, int Scale)? DecimalParametersHint { get; private set; }

    /// <inheritdoc/>
    public override string ToString()
    {
      return string.Format(ToStringFormat,
        base.ToString(), AggregateType, SourceIndex);
    }


    // Constructors

    /// <summary>
    /// Initializes a new instance of this class.
    /// </summary>
    /// <param name="name"><see cref="Name"/> property value.</param>
    /// <param name="index"><see cref="SourceIndex"/> property value.</param>
    /// <param name="aggregateType">The <see cref="AggregateType"/> property value.</param>
    public AggregateColumnDescriptor(string name, int index, AggregateType aggregateType)
    {
      Name = name;
      SourceIndex = index;
      AggregateType = aggregateType;
    }


    /// <summary>
    /// Initializes a new instance of this class.
    /// </summary>
    /// <param name="name"><see cref="Name"/> property value.</param>
    /// <param name="index"><see cref="SourceIndex"/> property value.</param>
    /// <param name="aggregateType">The <see cref="AggregateType"/> property value.</param>
    /// <param name="decimalParametersHint">Additional informantion about decimal column type.</param>
    public AggregateColumnDescriptor(string name, int index, AggregateType aggregateType, (int Precision, int Scale) decimalParametersHint) 
      : this(name, index, aggregateType)
    {
      DecimalParametersHint = decimalParametersHint;
    }
  }
}