export class ApiError extends Error {
  constructor(status, code, message, details = {}) {
    super(message);
    this.status = status;
    this.code = code;
    this.details = details;
  }
}

export const createError = (status, code, message, details = {}) => {
  throw new ApiError(status, code, message, details);
};

// Common errors
export const notFound = (resource) => {
  createError(404, 'RESOURCE_NOT_FOUND', `${resource} not found`);
};

export const badRequest = (message) => {
  createError(400, 'BAD_REQUEST', message);
};

export const unprocessable = (message, details) => {
  createError(422, 'UNPROCESSABLE_ENTITY', message, details);
};

export const conflict = (message) => {
  createError(409, 'CONFLICT', message);
};

export const unauthorized = (message) => {
  createError(401, 'UNAUTHORIZED', message);
};

export const forbidden = (message) => {
  createError(403, 'FORBIDDEN', message);
};

export const internalError = (message) => {
  createError(500, 'INTERNAL_SERVER_ERROR', message);
};
