<?php

namespace Daniv04\HaciendaPackage\Traits;

trait ResponseTrait
{
    protected function SuccessResponse($data, $message, $code): \Illuminate\Http\JsonResponse
    {
        return response()->json([
            'status' => 'success',
            'message' => $message,
            'data' => $data
        ], $code);
    }

    protected function PaginatedResponse($resourceCollection, string $message, int $code = 200): \Illuminate\Http\JsonResponse
    {
        $paginated = $resourceCollection->response()->getData(true);

        return response()->json([
            'status' => 'success',
            'message' => $message,
            'data' => $paginated['data'],
            'meta' => $paginated['meta'] ?? null,
            'links' => $paginated['links'] ?? null,
        ], $code);
    }

    protected function ErrorResponse($message, $code, $errors = []): \Illuminate\Http\JsonResponse
    {
        return response()->json([
            'status' => 'error',
            'message' => $message,
            'errors' => $errors
        ], $code);
    }
}