import { RESPONSE } from "@/lib/const"; interface ErrorResponse { error: { message: string; details?: unknown; }; } type SuccessResponse = T; type ResponseData = SuccessResponse | ErrorResponse; interface ResponseOptions { status?: number; } export class ResponseHelper { private data: ResponseData; private status: number; constructor(data: ResponseData, options: ResponseOptions = {}) { this.data = data; this.status = options.status || 200; } static success(data: T, status = RESPONSE.SUCCESS.STATUS): Response { return new ResponseHelper(data, { status }).toResponse(); } static error( constant: (typeof RESPONSE)[keyof typeof RESPONSE], details?: unknown ): Response { return new ResponseHelper( { error: { message: constant.MESSAGE, details } }, { status: constant.STATUS } ).toResponse(); } toResponse(): Response { return Response.json(this.data, { status: this.status, }); } }