<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class TestLoggingCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'logging:test {--level=info} {--message=Test log message}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test the logging system by creating test log entries';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $level = $this->option('level');
        $message = $this->option('message');

        $this->info("Testing logging system with level: {$level}");
        $this->info("Message: {$message}");

        // Test different log channels
        switch ($level) {
            case 'emergency':
            case 'alert':
            case 'critical':
            case 'error':
                Log::channel('error_email')->{$level}($message, [
                    'test' => true,
                    'timestamp' => now(),
                    'command' => 'logging:test'
                ]);
                break;

            case 'warning':
                Log::channel('security')->warning($message, [
                    'test' => true,
                    'timestamp' => now(),
                    'command' => 'logging:test'
                ]);
                break;

            case 'notice':
            case 'info':
            case 'debug':
            default:
                Log::channel('application')->{$level}($message, [
                    'test' => true,
                    'timestamp' => now(),
                    'command' => 'logging:test'
                ]);
                break;
        }

        $this->info("Log entry created successfully!");
        $this->info("Check the logs at: /logging");

        return Command::SUCCESS;
    }
}
