<?php

namespace Dits\CaW\Rest;

use Dits\CaW\Modules\Compare;

class CompareTableRoute extends AbstractRoute {

    private Compare $compare;

    public function __construct(Compare $compare) {
        $this->compare = $compare;
    }

    public function get_path(): string {
        return 'compare/table';
    }

    public function get_arguments(): array {
        return [
            'category_id' => [
                'required' => false,
                'validate_callback' => function($param, $request, $key) {
                    return is_numeric($param);
                }
            ]
        ];
    }

    public function get_methods(): string {
        return 'GET';
    }

    public function permission(): bool {
        return true;
    }

    public function respond(\WP_REST_Request $request): OkResponse {
        $category_id = $request->get_param('category_id');
        return new OkResponse($this->compare->table($category_id));
    }
}


