unit MathService;

interface

uses
  XData.Service.Common;

type
  /// <summary>
  ///  An interface that provides arithmentic functions. This documentation
  ///  doesn not appear in Swagger, because we use <c>swagger</c> tags
  /// </summary>
  /// <swagger name="tag-name">Arithmetic</swagger>
  /// <swagger name="tag-description">
  ///  Common arithmetic operations
  /// </swagger>
  [ServiceContract]
  [Route('arith')]
  IArithmeticService = interface(IInvokable)
    ['{9E343ABD-D97C-4411-86BF-AD2E13BE71F3}']

    /// <summary>
    ///   This is internal documentation for the Add method. It will be used by Delphi (code insight)
    ///   and other documentation tools. It's not used for swagger because we are using
    ///   the "swagger" tag for the summary
    /// </summary>
    /// <param name="A">
    ///   Description for A parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    /// <param name="B">
    ///   Description for B parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    ///
    /// <swagger>
    ///   Adds one number to the other
    /// </swagger>
    /// <swagger name="param-A">
    ///   The first value to be added
    /// </swagger>
    /// <swagger name="param-B">
    ///   Second value to be added
    /// </swagger>
    /// <swagger name="remarks">
    /// This operation returns the sum of A and B parameters.
    ///
    /// - If both values are **zero**, then the result is **0**.
    ///
    /// Example:
    ///
    ///     GET /math/add?A=2&#65286;B=4
    ///
    /// You can use both *integer* and *floating-point* numbers.
    /// </swagger>
    [HttpGet] function Add(A, B: Double): Double;

    /// <summary>
    ///   This is internal documentation for the Subtract method. It will be used by Delphi (code insight)
    ///   and other documentation tools. It's not used for swagger because we are using
    ///   the "swagger" tag for the summary
    /// </summary>
    /// <param name="A">
    ///   Description for A parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    /// <param name="B">
    ///   Description for B parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    ///
    /// <swagger>
    ///   Subtracts one number from another
    /// </swagger>
    /// <swagger name="param-A">
    ///   The number from which the subtrahend is to be subtracted (minuend)
    /// </swagger>
    /// <swagger name="param-B">
    ///   The value that is to be subtracted (subtrahend)
    /// </swagger>
    /// <swagger name="remarks">
    /// This operation returns the subtraction of B from A - i.e., A minus B.
    ///
    /// - If both values are **zero**, then the result is **0**.
    /// - If B is **lower** than B, the result will be **negative**.
    ///
    /// Example:
    ///
    ///     GET /math/add?A=5&#65286;B=2
    ///
    /// You can use both *integer* and *floating-point* numbers.
    /// </swagger>
    [HttpGet] function Subtract(A, B: Double): Double;

    /// <summary>
    ///   This is internal documentation for the Power method. It will be used by Delphi (code insight)
    ///   and other documentation tools. It's not used for swagger because we are using
    ///   the "swagger" tag for the summary
    /// </summary>
    /// <param name="Base">
    ///   Description for Base parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    /// <param name="Exponent">
    ///   Description for Exponent parameter. Only method documentation, doesn't appear in Swagger.
    /// </param>
    ///
    /// <swagger>
    ///   Raises a base number to an exponent power
    /// </swagger>
    /// <swagger name="param-Base">
    ///   The base value for the power operation.
    /// </swagger>
    /// <swagger name="param-Exponent">
    ///   The exponent value.
    /// </swagger>
    /// <swagger name="remarks">
    /// This operation returns the value of the Base parameter raised to the power of the Exponent parameter.
    ///
    /// - If the exponent is **zero**, then the result is **1.0**.
    /// - If the exponent is **1**, then the result is the same as the **first argument**.
    ///
    /// Example:
    ///
    ///     GET /math/power?Base=2&#65286;Exponent=4
    ///
    /// For fractional exponents, base *must be greater* than 0.
    /// </swagger>
    [HttpGet] function Power(Base, Exponent: Double): Double;

    /// <summary>
    ///   Documentation for NotThisFunctionPlease. It will not be in Swagger
    ///   because we are using SwaggerExclude attribute
    /// </summary>
    [SwaggerExclude]
    [HttpGet] function NotThisFunctionPlease: Integer;
  end;

  /// Common trigonometric operations
  /// <swagger name="tag-name">Trigonometry</swagger>
  [ServiceContract]
  [Route('trig')]
  ITrigonometryService = interface(IInvokable)
    ['{B9BB0872-A63A-4D06-BF21-3DB1F8A6699A}']
    /// <summary>
    ///   Retrieves the sine (sin) of an angle
    /// </summary>
    /// <remarks>
    ///  Returns the Sine (Sin) value of an angle radians value.
    ///  The value returned will be between -1 and 1.
    ///  If the angle is zero, the returned value will be zero.
    /// </remarks>
    /// <param name="Angle">
    ///   The angle in radians.
    /// </param>
    [HttpGet] function Sin(Angle: Double): Double;

    /// <summary>
    ///   Retrieves the cosine (cos) of an angle
    /// </summary>
    /// <remarks>
    ///  Returns the Cosine (Cos) value of an angle radians value.
    ///  The value returned will be between -1 and 1.
    ///  If the angle is zero, the returned value will be zero.
    /// </remarks>
    /// <param name="Angle">
    ///   The angle in radians.
    /// </param>
    [HttpGet] function Cos(Angle: Double): Double;
  end;

implementation

initialization
  RegisterServiceType(TypeInfo(IArithmeticService));
  RegisterServiceType(TypeInfo(ITrigonometryService));
end.
