   constructor: (@options) ->
     @resourceName = @options.name || 'myResource'
     @moduleName = "#{@resourceName.toLowerCase()}"
+    @scriptExt = @options.otherOptions.scriptExt || null
 
   @usageParams: ->
     "<resourceName>"

    """

  generate: ->
    return new Promise (resolve, reject) =>
      path = require "path"
      paths = require "../paths"


      intendedModulePath = path.join paths.application.appDir, @moduleName

      # TODO: should structure differently
      if @scriptExt != null
        @do_generation(resolve)

      else
        inquirer = require "inquirer"

        if fs.existsSync intendedModulePath
          reject new Error "Scaffold already exists for resource #{@resourceName}."
          return

        scriptExtPrompt =
          type: "list"
          name: "scriptExt"
          message: "Do you want your scaffold to be generated with CoffeeScript or JavaScript files?"
          choices: [
            { name: "CoffeeScript", value: "coffee" }
            { name: "JavaScript", value: "js"}
          ]
          default: "coffee"

        promptList = [
          scriptExtPrompt
        ]

        inquirer.prompt promptList, (answers) =>
          @scriptExt = answers.scriptExt

          @do_generation(resolve)

  do_generation: (resolve) ->
    #TODO: should be Resource.forName but Resource cannot require Provider if Provider requires Resource
    Provider.resourceForName(@resourceName).then (resource)=>

      @fields = resource.getFieldNamesSync()

      if @fields.length == 0
        reject new Error "No fields defined for resource #{@resourceName}."
        return

      steroidsCli.debug "DataModuleGenerator", "Generating scaffold with name: #{@resourceName} modulename: #{@modulename} and fields: #{JSON.stringify(@fields)}"

      steroidsGenerators.dataModule {
        @moduleName
        @resourceName
        @scriptExt
        @fields
      }, ->
        steroidsCli.debug "DataModuleGenerator", "Generated Scaffold for #{@resourceName}"
        resolve()

module.exports = DataModuleGenerator
