#!/usr/bin/env ruby

# Run it like this:
#
#   ./codegen/typed_source_generator.rb > src/main/scala/com/twitter/scalding/typed/GeneratedTypedSource.scala

$indent = "  "

TYPES = ('A'..'Z').to_a

def make_typed_source(cnt)
  other_cnts = (1..(22-cnt)).to_a
  typeString = TYPES[0..(cnt - 1)].join(",")
  puts "trait TypedSource#{cnt}[#{typeString}] extends TypedSource[Tuple#{cnt}[#{typeString}]] {"
  puts "#{$indent}def converter[Z >: Tuple#{cnt}[#{typeString}]] = TupleConverter.asSuperConverter(TupleConverter.of[Tuple#{cnt}[#{typeString}]])"
  puts "}"
end

def make_typed_sink(cnt)
  other_cnts = (1..(22-cnt)).to_a
  typeString = TYPES[0..(cnt - 1)].join(",")
  puts "trait TypedSink#{cnt}[#{typeString}] extends TypedSink[Tuple#{cnt}[#{typeString}]] {"
  puts "#{$indent}final def setter[Z <: Tuple#{cnt}[#{typeString}]] = TupleSetter.asSubSetter(TupleSetter.of[Tuple#{cnt}[#{typeString}]])"
  puts "}"
end

puts "// following were autogenerated by #{__FILE__} at #{Time.now} do not edit"
puts %q|package com.twitter.scalding

|

(1..22).each { |c|
  make_typed_source(c)
  puts
}

(1..22).each { |c|
  make_typed_sink(c)
  puts
}

puts "// end of autogenerated"
