<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use App\Models\Notification;
use Carbon\Carbon;

class DeleteNotification extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:delete-notification';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Delete notifications older than 30 days (soft delete)';

    /**
     * Execute the console command.
     */

    public function handle()
    {
      $this->info('🧹 Starting notification cleanup...');

        $dateThreshold = Carbon::now()->subDays(30);

        // Soft delete (update deleted_at) for notifications older than 30 days
        $deletedCount = Notification::where('created_at', '<', $dateThreshold)->delete();

        $this->info("✅ Deleted {$deletedCount} old notifications successfully.");

        Log::info("Deleted {$deletedCount} old notifications older than 30 days.");

        return 0;
    }
}
