<?php

namespace App\Console\Commands;

use App\Models\ChatMessage;
use Illuminate\Console\Command;

class CleanupOldChatMessages extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'chat:cleanup-old-messages {--days=30 : Kaç günden eski mesajları silinsin}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Belirli tarihten eski sohbet mesajlarını sil';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $days = $this->option('days');
        $cutoffDate = now()->subDays($days);

        $deleted = ChatMessage::where('created_at', '<', $cutoffDate)->delete();

        $this->info("✅ {$deleted} eski mesaj silindi ({$days} günden eski).");
        
        return Command::SUCCESS;
    }
}
