<?php

namespace App\Controllers\Api;

use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;

class BaseApiController extends BaseController
{
    protected function respondSuccess(
        $data = [],
        string $message = 'Success',
        int $code = ResponseInterface::HTTP_OK
    ) {
        return $this->response->setStatusCode($code)->setJSON([
            'status'  => true,
            'message' => $message,
            'data'    => $data
        ]);
    }

    protected function respondError(
        string $message = 'Error',
        int $code = ResponseInterface::HTTP_BAD_REQUEST,
        $errors = null
    ) {
        return $this->response->setStatusCode($code)->setJSON([
            'status'  => false,
            'message' => $message,
            'errors'  => $errors
        ]);
    }

    protected function getJsonInput()
    {
        return $this->request->getJSON(true);
    }

    protected function writeLog(string $aktivitas)
{
    $user = $this->request->user ?? null;

    if ($user && isset($user['id_user'])) {
        logAktivitas($user['id_user'], $aktivitas);
    }
}

}