<?php

namespace Fotogenic_AI;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

final class Bulk_Cache_Version {
    private const OPTION_KEY = 'fotogenic_ai_bulk_cache_version';
    private const CACHE_GROUP = 'fotogenic_ai';

    public static function get(): int {
        $cached = wp_cache_get( self::OPTION_KEY, self::CACHE_GROUP );
        if ( is_numeric( $cached ) ) {
            return (int) $cached;
        }
        $version = get_option( self::OPTION_KEY, 0 );
        $version = is_numeric( $version ) ? (int) $version : 0;
        wp_cache_set( self::OPTION_KEY, $version, self::CACHE_GROUP );
        return $version;
    }

    public static function bump(): int {
        $next = time();
        update_option( self::OPTION_KEY, $next, false );
        wp_cache_set( self::OPTION_KEY, $next, self::CACHE_GROUP );
        return $next;
    }
}
