const { logout } = require('../lib/auth')
const chalk = require('chalk')

async function logoutCommand() {
  try {
    const deleted = await logout()

    if (deleted) {
      console.log(chalk.green('✓ Logged out successfully. Token removed from keychain.'))
    } else {
      console.log(chalk.yellow('No stored token found. You were not logged in.'))
      console.log(chalk.dim('If using BILD_TOKEN or CMS_TOKEN, unset those variables.'))
    }
  } catch (error) {
    console.error(chalk.red(`Error: ${error.message}`))
    process.exit(1)
  }
}

module.exports = logoutCommand
