import strings from "@/utils/strings";

/**
 * Base error class.
 */
class BaseError extends Error {
	constructor(message?: string) {
		// Pass the message to the Error constructor
		super(message);

		// Set the name of the error
		this.name = this.constructor.name;

		// Capture the stack trace
		if (Error.captureStackTrace) {
			Error.captureStackTrace(this, this.constructor);
		} else {
			this.stack = new Error(message).stack;
		}
	}
}

/**
 * Permission error class.
 */
export class PermissionError extends BaseError {
	constructor() {
		super(strings.ERROR.PERMISSION);
	}
}

/**
 * Authentication error class.
 */
export class AuthenticationError extends BaseError {
	constructor() {
		super(strings.ERROR.NO_SESSION);
	}
}

/**
 * Validation error class.
 */
export class ValidationError extends BaseError {
	constructor() {
		super(strings.ERROR.VALIDATION);
	}
}

/**
 * Not found error class.
 */
export class NotFoundError extends BaseError {
	constructor() {
		super(strings.ERROR.NOT_FOUND);
	}
}

export default BaseError;
