<?php

namespace App\Console\Commands;

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

class CleanupExpiredLinks extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'storage:cleanup-links';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Delete expired share links older than 7 days';

    /**
     * Execute the console command.
     */
    public function handle(): int
    {
        $threshold = now()->subDays(7);

        $deleted = DB::table('file_share_links')
            ->where('expires_at', '<', $threshold)
            ->delete();

        $this->info("Deleted {$deleted} expired share links");

        return Command::SUCCESS;
    }
}
