<?php

namespace App\Traits;

use Illuminate\Http\JsonResponse;

trait ApiResponse
{
    /**
     * Respons sukses standar
     */
    protected function successResponse($data, $message = "Operation successful", $code = 200): JsonResponse
    {
        return response()->json([
            'status'  => 'success',
            'message' => $message,
            'data'    => $data,
            'error'   => null
        ], $code);
    }

    /**
     * Respons error standar
     */
    protected function errorResponse($message = "An error occurred", $code = 400, $errorDetails = null): JsonResponse
    {
        return response()->json([
            'status'  => 'error',
            'message' => $message,
            'data'    => null,
            'error'   => $errorDetails
        ], $code);
    }
}