<?php namespace App\Controllers;

use CodeIgniter\RESTful\ResourceController;
use CodeIgniter\API\ResponseTrait;

class BaseApiController extends ResourceController
{
    use ResponseTrait;

    protected function respondError($statusCode, $errorKey, $message, $errors = null)
    {
        $payload = [
            'status'  => $statusCode,
            'error'   => $errorKey,
            'message' => $message,
        ];
        if ($errors) {
            $payload['errors'] = $errors;
        }
        return $this->respond($payload, $statusCode);
    }
}
