import { DataPointClass, MCFunctionClass, NamespacedString, PredicateClass, Score } from 'sandstone'
import { SandstoneCore } from 'sandstone/core'

class Float {

  add(value: Float | Integer): this

  add(values: (Float | Integer)[]): this

  add(...values: (Float | Integer)[]): this

  add(...args: [Float | Integer | (Float | Integer)[]] | (Float | Integer)[]) {
    // TODO

    return this
  }

  subtract(value: Float | Integer) {
    // TODO

    return this
  }

  multiply(value: Float | Integer): this

  multiply(values: (Float | Integer)[]): this

  multiply(...values: (Float | Integer)[]): this

  multiply(...args: [Float | Integer | (Float | Integer)[]] | (Float | Integer)[]) {
    // TODO

    return this
  }

  divide(value: Float | Integer) {
    // TODO

    return this
  }

  modulo(value: Float | Integer) {
    // TODO

    return this
  }
}

class Integer {

  add(value: Float | Integer): this

  add(values: (Float | Integer)[]): this

  add(...values: (Float | Integer)[]): this

  add(...args: [Float | Integer | (Float | Integer)[]] | (Float | Integer)[]) {
    // TODO

    return this
  }

  subtract(value: Float | Integer) {
    // TODO

    return this
  }

  multiply(value: Float | Integer): this

  multiply(values: (Float | Integer)[]): this

  multiply(...values: (Float | Integer)[]): this

  multiply(...args: [Float | Integer | (Float | Integer)[]] | (Float | Integer)[]) {
    // TODO

    return this
  }

  divide(value: Float | Integer, floored = true) {
    // TODO

    return this
  }

  modulo(value: Float | Integer, floored = true) {
    // TODO

    return this
  }
}

export class SandstoneMath {
  constructor(public sandstoneCore: SandstoneCore) {}

  // Basics // TODO

  float(init: number | Score | DataPointClass | Float | Integer = 0) {
    // TODO
  }

  integer(init: number | Score | DataPointClass | Float | Integer = 0) {
    // TODO
  }

  // Operations // TODO

  sum(values: Float[]): Float

  sum(...values: Float[]): Float

  sum(values: Integer[]): Integer

  sum(...values: Integer[]): Integer

  sum(values: (Float | Integer)[]): Float

  sum(...values: (Float | Integer)[]): Float

  sum(values: (Float | Integer)[], result: 'float'): Float

  sum(values: (Float | Integer)[], result: 'integer'): Integer

  sum(...args: ((Float | Integer)[] | Float | Integer | 'float' | 'integer')[]) {
    // TODO
  }

  subtract(a: Float, b: Float | Integer): Float

  subtract(a: Integer, b: Float | Integer): Integer

  subtract(a: Float | Integer, b: Float | Integer) {
    // TODO
  }

  product(values: Float[]): Float

  product(...values: Float[]): Float

  product(values: Integer[]): Integer

  product(...values: Integer[]): Integer

  product(values: (Float | Integer)[]): Float

  product(...values: (Float | Integer)[]): Float

  product(values: (Float | Integer)[], result: 'float'): Float

  product(values: (Float | Integer)[], result: 'integer'): Integer

  product(...args: ((Float | Integer)[] | Float | Integer | 'float' | 'integer')[]) {
    // TODO
  }

  divide(a: Float, b: Float | Integer): Float

  divide(a: Integer, b: Float | Integer, floored?: boolean): Integer

  divide(a: Float | Integer, b: Float | Integer) {
    // TODO
  }

  modulo(a: Float, b: Float | Integer): Float

  modulo(a: Integer, b: Float | Integer, floored?: boolean): Integer

  modulo(a: Float | Integer, b: Float | Integer) {
    // TODO
  }

  abs(value: Float): Float

  abs(value: Integer): Integer

  abs(value: Float | Integer) {
    // TODO
  }

  exponentiate(a: Float, b: Float | Integer): Float

  exponentiate(a: Integer, b: Float | Integer): Integer

  exponentiate(a: Float | Integer, b: Float | Integer) {
    // TODO
  }

  sqrt(value: Float) {
    // TODO
  }

  vectorLength(components: Float[]): Float

  vectorLength(...components: Float[]): Float

  vectorLength(components: (Float | Integer)[]): Float

  vectorLength(...components: (Float | Integer)[]): Float

  vectorLength(...args: ((Float | Integer)[] | Float | Integer)[]) {
    // TODO
  }

  ceil(value: Float) {
    // TODO
  }

  truncate(value: Float) {
    // TODO
  }

  round(value: Float) {
    // TODO
  }

  floor(value: Float) {
    // TODO
  }

  average(values: Float[]): Float

  average(...values: Float[]): Float

  average(values: Integer[]): Integer

  average(...values: Integer[]): Integer

  average(values: (Float | Integer)[]): Float

  average(...values: (Float | Integer)[]): Float

  average(values: (Float | Integer)[], result: 'float'): Float

  average(values: (Float | Integer)[], result: 'integer'): Integer

  average(...args: ((Float | Integer)[] | Float | Integer | 'float' | 'integer')[]) {
    // TODO
  }

  sine(angle: Float) {
    // TODO
  }

  arcSine(ratio: Float) {
    // TODO
  }

  cosine(angle: Float) {
    // TODO
  }

  arcCosine(ratio: Float) {
    // TODO
  }

  // Utilities // TODO

  random(range: { min?: Float | Integer, max?: Float | Integer } = {}, result: 'float' | 'integer' = 'float') {
    // TODO
  }

  pick(values: { value: Float, weight: number | Float }[] | { value: Integer, weight: number | Float }[]) {
    // TODO
  }

  enchantmentLevel() {
    // TODO
  }

  environmentAttribute() {
    // TODO
  }

  // Flow // TODO

  if(condition: Condition, callback: () => void): IfStatement<false>
  if(condition: Condition): IfStatement<true>
  if(
    condition: Condition,
    callback?: () => void,
  ): IfStatement<boolean> {
    // TODO
  }

  /**
   * Combine conditions with AND.
   *
   * Accepts either variadic conditions (`_.and(a, b, c)`) or a single array
   * (`_.and([a, b, c])`, useful for `Array.prototype.map` results).
   */
  and(...conditions: Condition[]): AndNode
  and(conditions: Condition[]): AndNode
  and(...args: any[]): AndNode {
    // TODO
  }

  /**
   * Combine conditions with OR.
   *
   * Accepts either variadic conditions (`_.or(a, b, c)`) or a single array
   * (`_.or([a, b, c])`, useful for `Array.prototype.map` results).
   */
  or(...conditions: Condition[]): OrNode
  or(conditions: Condition[]): OrNode
  or(...args: any[]): OrNode {
    // TODO
  }

  not = (condition: Condition) => new NotNode(this.sandstoneCore, conditionToNode(condition))

  return() {
    // TODO
  }

  while(condition: Condition, callback: () => void) {
    return new WhileStatement(this.sandstoneCore, conditionToNode(condition), callback)
  }

  for(
    initial: number | Score,
    end: (iterator: Score) => Condition,
    iterate: (iterator: Score) => Score,
    callback: (iterator: Score | number, _continue: () => void) => any,
  ): ForIStatement

  for(
    range: [start: number | Score, end: number | Score],
    type: 'iterate',
    callback: (iterator: Score, _continue: () => void) => any,
  ): ForIStatement

  for(
    arg1: (number | Score) | [start: number | Score, end: number | Score],
    arg2: ((iterator: Score) => Condition) | 'iterate',
    arg3:
      | ((iterator: Score) => Score)
      | ((iterator: Score, _continue: () => void) => any),
    arg4?: ((iterator: Score, _continue: () => void) => any)
  ) {
    // TODO
  }

  switch<ValueType extends Float | Integer>(value: ValueType, cases: CaseStatement<ValueType> | DefaultType<ValueType>): void

  switch<ValueType extends Float | Integer>(
    value: ValueType,
    cases: SwitchCase<ValueType>[] | [...SwitchCase<ValueType>[], ['default', () => any]]
  ): void

  switch<ValueType extends Float | Integer>(
    value: ValueType,
    cases: SwitchCase<ValueType>[] | [...SwitchCase<ValueType>[], ['default', () => any]] | CaseStatement<ValueType> | DefaultType<ValueType>,
  ) {
    // TODO
  }

  case<SwitchValueType extends Float | Integer>(value: Condition<SwitchValueType>, callback: () => any) {
    // TODO
  }

  // Conditions // TODO

  mcfunction = (mcfunction: NamespacedString | MCFunctionClass<undefined, undefined>) => {
    // TODO
  }

  predicate = (predicate: NamespacedString | PredicateClass) => {
    // TODO
  }
}
