<?php

namespace SmartPay\Modules\Admin;
defined('ABSPATH') || exit;

use SmartPay\Http\Controllers\Rest\Admin\DashboardController;
use SmartPay\Http\Controllers\Rest\Admin\ReportController;
use WP_REST_Server;

class Report
{
    protected $app;

    public function __construct($app)
    {
        $this->app = $app;
        $this->app->addAction('rest_api_init', [$this, 'registerRestRoutes']);
    }

    public function registerRestRoutes()
    {
        $reportController    = $this->app->make(ReportController::class);
        $dashboardController = $this->app->make(DashboardController::class);

        register_rest_route('smartpay/v1', 'reports', [
            [
                'methods'             => WP_REST_Server::READABLE,
                'callback'            => [$reportController, 'index'],
                'permission_callback' => [$reportController, 'middleware'],
            ],
        ]);

        register_rest_route('smartpay/v1', 'dashboard', [
            [
                'methods'             => WP_REST_Server::READABLE,
                'callback'            => [$dashboardController, 'index'],
                'permission_callback' => [$dashboardController, 'middleware'],
            ],
        ]);
    }
}
