# frozen_string_literal: true

require "thor"

require_relative "list"
require_relative "create"
require_relative "../../sub_command_base"

module Neetob
  class CLI
    module Github
      module Issues
        class Commands < SubCommandBase
          class_option :repos,
            {
              type: :array, aliases: "-r", required: true,
              desc: "Github repo names. Can be matched using the '*' wildcard. Example: \"neeto*\" \"neeto-cal-web\", also providing \"all\" as value matches all neeto repos."
            }

          desc "list", "List the issues in the Github repos"
          option :state, type: :string, default: "open", aliases: "-s", desc: "State of the issues. Can be open or closed."
          option :assignee, type: :string, desc: "Username of the current assignee. Can also use \"none\"."
          option :label, type: :string, aliases: "-l", desc: "Label name to filter out the issues"
          option :count, type: :boolean, aliases: "-c", desc: "Also shows the count of issues"
          option :search, type: :string, desc: "Can provide custom query to filter or sort issues. Example: \"created:2022-11-07..2022-11-08 sort:comments-asc\""
          def list
            List.new(
              options[:repos], options[:assignee], options[:state], options[:search], options[:count],
              options[:label], options[:sandbox]).run
          end

          desc "create", "Create a issue in the Github repos"
          option :title, type: :string, aliases: "-t", desc: "Title of the issue"
          option :description, type: :string, aliases: "-d", desc: "Description of the issue"
          option :assignee, type: :string, desc: "Username of the user you want to assign this issue."
          option :labels, type: :string, desc: "List of comma separated labels you want to add in this issue. Example: \"--labels bug,ui\""
          def create
            Create.new(
              options[:repos],
              options[:title],
              options[:description],
              options[:assignee],
              options[:labels],
              options[:sandbox]
            ).run
          end
        end
      end
    end
  end
end