import {
    Schema,
    SchemaValidationError,
    ValidationErrorDetail,
    z,
} from "@shared/utils/validator.ts";

export class ErrorBase extends Error {
    constructor(message: string = "An unknown error has occurred") {
        super(message);
        this.name = this.constructor.name;
    }
}

export class QueryExecutionError extends ErrorBase {
    public readonly type = "QueryExecutionError";
    constructor(message: string) {
        super(message);
    }
}

export class NoAdminEntryError extends ErrorBase {
    public readonly type = "NoAdminEntry";
    constructor(message: string) {
        super(message);
    }
}

export class FailedToReadFileError extends ErrorBase {
    public readonly type = "FailedToReadFileError";
    constructor(message: string) {
        super(message);
    }
}

export class InvalidSyntaxError extends ErrorBase {
    public readonly type = "InvalidSyntax";
    constructor(message: string) {
        super(message);
    }
}

export class InvalidPathError extends ErrorBase {
    public readonly type = "InvalidPath";
    constructor(message: string) {
        super(message);
    }
}

export class AdminPasswordNotSetError extends ErrorBase {
    public readonly type = "AdminPasswordNotSetError";
    constructor(message: string) {
        super(message);
    }
}

export class RequestValidationError extends SchemaValidationError {
    public readonly type = "RequestValidationError";
    constructor(
        input: unknown,
        detail: ValidationErrorDetail,
    ) {
        super(input, detail);
    }
}

export class ResponseValidationError extends SchemaValidationError {
    public readonly type = "ResponseValidationError";
    constructor(
        input: unknown,
        detail: ValidationErrorDetail,
    ) {
        super(input, detail);
    }
}

export class FailedToParseRequestAsJSON extends ErrorBase {
    public readonly type = "FailedToParseRequestAsJSON";
    constructor(message: string) {
        super(message);
    }
}
