<?php

namespace Formatrica\Setup;

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

use Formatrica\Forms\Form_Post_Type;
use Formatrica\Submission\Integration_Queue;
use Formatrica\Submission\Submission_Cleanup;

final class Setup_Service_Provider implements Service_Provider
{
    public function register(Service_Locator $services): void
    {
        // Run pending schema migrations for sites upgraded via plugin update
        // (Activator only runs on activation). needs_upgrade() short-circuits to
        // a single get_option once the version is current, so this is cheap.
        $schema = new Schema_Manager();
        if ($schema->needs_upgrade()) {
            $schema->run_migrations();
        }

        $submission_cleanup = new Submission_Cleanup();
        $submission_cleanup->boot();

        // Initialize async integration queue for background webhook processing
        $integration_queue = new Integration_Queue();
        $integration_queue->register_hooks();

        // Note: Form_Post_Type is no longer used as forms are now stored in custom table
        // Kept in Services for backward compatibility reference
        $services->set(Submission_Cleanup::class, $submission_cleanup);
        $services->set(Integration_Queue::class, $integration_queue);
    }
}
