<?php

namespace Fotogenic_AI;

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

final class Rest_Credits {
    private Service_Credits $service;

    public function __construct( Service_Credits $service ) {
        $this->service = $service;
    }

    public function register_routes( Rest_Router $router ): void {
        $router->register_route(
            'fotogenic-ai/v1',
            '/credits/refresh',
            [
                'methods'             => 'POST',
                'callback'            => [ $this, 'handle_credits_refresh' ],
                'permission_callback' => [ $router, 'permissions_admin' ],
            ]
        );

        $router->register_route(
            'fotogenic-ai/v1',
            '/credits/status',
            [
                'methods'             => 'GET',
                'callback'            => [ $this, 'handle_credits_status' ],
                'permission_callback' => [ $router, 'permissions_admin' ],
            ]
        );
    }

    public function handle_credits_refresh( \WP_REST_Request $request ) {
        return $this->service->handle_credits_refresh( $request );
    }

    public function handle_credits_status( \WP_REST_Request $request ) {
        return $this->service->handle_credits_status( $request );
    }
}
