# The MIT License (MIT)

# Copyright (c) 2023 Mike DeAngelo Google, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# frozen_string_literal: true

require 'thor'

module Gzr
  module Commands
    class Session < Thor

      namespace :session

      desc 'login', 'Create a persistent session'
      method_option :text, type: :boolean, default: false,
                           desc: 'output token to screen instead of file'
      def login(*)
        if options[:help]
          invoke :help, ['login']
        else
          require_relative 'session/login'
          Gzr::Commands::Session::Login.new(options).execute
        end
      end

      desc 'logout', 'End a persistent session'
      def logout(*)
        if options[:help]
          invoke :help, ['logout']
        else
          require_relative 'session/logout'
          Gzr::Commands::Session::Logout.new(options).execute
        end
      end

      desc 'get', 'Get data about current session'
      def get(*)
        if options[:help]
          invoke :help, ['get']
        else
          require_relative 'session/get'
          Gzr::Commands::Session::Get.new(options).execute
        end
      end

      desc 'update WORKSPACE_ID', 'change the workspace_id of the current session'
      def update(workspace_id)
        if options[:help]
          invoke :help, ['update']
        else
          require_relative 'session/update'
          Gzr::Commands::Session::Update.new(workspace_id,options).execute
        end
      end

    end
  end
end
