<?php

namespace SoftminalB2B\Http\Controllers;

use SoftminalB2B\Http\Sanitizer\RequestSanitizer;

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

abstract class Controller
{
    protected function response($data, $status = 200)
    {
        return new \WP_REST_Response($data, $status);
    }

    protected function success($data = null, $message = 'Success')
    {
        return $this->response([
            'success' => true,
            'message' => $message,
            'data'    => $data
        ]);
    }

    protected function error($message = 'Something went wrong', $status = 400)
    {
        return $this->response([
            'success' => false,
            'message' => $message
        ], $status);
    }

    protected function notFound($message = 'Resource not found')
    {
        return $this->error($message, 404);
    }

    protected function validate(\WP_REST_Request $request, array $rules = [])
    {
        return RequestSanitizer::sanitizeRequest($request, $rules);
    }
}
