require 'thor'

module Belajar
  module Terminal

    require_relative 'courses'
    require_relative 'solutions'
    require_relative 'setup'
    require_relative 'output'

    class CLI < Thor
      include Terminal::Output

      desc 'courses [COMMAND]', 'Handle belajar courses'
      subcommand 'courses', Terminal::Courses

      desc 'solutions [COMMAND]', 'Handle your solutions'
      subcommand 'solutions', Terminal::Solutions

      desc 'setup [COMMAND]', 'Change belajar setup'
      subcommand 'setup', Terminal::Setup

      def self.start
        Belajar.config.import!
        super
      end

      desc 'about', 'About belajar'
      def about
        Welcome.about
      end

      desc 'welcome', 'Setup belajar the first time and learn some important commands.'
      def welcome
        Welcome.run
      end

      desc 'scaffold', 'Scaffold solution files for your courses.'
      def scaffold
        generator = Generator.new
        generator.prepare

        courses_path = Belajar.config.courses_path
        solutions_path = Belajar.config.solutions_path

        generator.scaffold(courses_path, solutions_path)

        say_info "You will find your solution files in\n#{solutions_path}."
      end

      desc 'learn', 'Go to belajar to learn Ruby!'
      def learn
        courses = Loading::Courses.load(Belajar.config.courses_path)
        courses.empty? ? Courses.new.list : Belajar.start
      end
    end

  end
end