<?php
declare(strict_types=1);

namespace CronJobs;

use App\Core\Database;

class MakeupCreditExpiryJob
{
    private Database $db;
    public function __construct(Database $db) { $this->db = $db; }

    public function shouldRun(): bool
    {
        return true; // Daily
    }

    public function run(): array
    {
        $result = $this->db->query(
            "UPDATE makeup_credits
             SET status = 'expired'
             WHERE status = 'available'
               AND expires_at IS NOT NULL
               AND expires_at < CURDATE()"
        );

        $count = $result->rowCount();

        return [
            'status'  => 'success',
            'message' => "Expired {$count} makeup credits.",
        ];
    }
}
