import { InferSchemaType, z } from "@shared/utils/validator.ts";
import { createErrorFactory, defineError } from "@shared/utils/errors.ts";

export const queryExecutionErrorSchema = defineError(
    "QueryExecutionError",
);
export const queryExecutionError = createErrorFactory(
    queryExecutionErrorSchema,
);
export type QueryExecutionError = InferSchemaType<
    typeof queryExecutionErrorSchema
>;

export const noAdminEntryErrorSchema = defineError("NoAdminEntryError");
export const noAdminEntryError = createErrorFactory(noAdminEntryErrorSchema);
export type NoAdminEntryError = InferSchemaType<typeof noAdminEntryErrorSchema>;

export const failedToReadFileErrorSchema = defineError("FailedToReadFileError");
export const failedToReadFileError = createErrorFactory(
    failedToReadFileErrorSchema,
);
export type FailedToReadFileError = InferSchemaType<
    typeof failedToReadFileErrorSchema
>;

export const invalidSyntaxErrorSchema = defineError("InvalidSyntaxError");
export const invalidSyntaxError = createErrorFactory(invalidSyntaxErrorSchema);
export type InvalidSyntaxError = InferSchemaType<
    typeof invalidSyntaxErrorSchema
>;

export const invalidPathErrorSchema = defineError("InvalidPathError");
export const invalidPathError = createErrorFactory(invalidPathErrorSchema);
export type InvalidPathError = InferSchemaType<typeof invalidPathErrorSchema>;

export const adminPasswordNotSetErrorSchema = defineError(
    "AdminPasswordNotSetError",
);
export const adminPasswordNotSetError = createErrorFactory(
    adminPasswordNotSetErrorSchema,
);
export type AdminPasswordNotSetError = InferSchemaType<
    typeof adminPasswordNotSetErrorSchema
>;

export const requestValidationErrorSchema = defineError(
    "RequestValidationError",
);
export const requestValidationError = createErrorFactory(
    requestValidationErrorSchema,
);
export type RequestValidationError = InferSchemaType<
    typeof requestValidationErrorSchema
>;

export const responseValidationErrorSchema = defineError(
    "ResponseValidationError",
);
export const responseValidationError = createErrorFactory(
    responseValidationErrorSchema,
);
export type ResponseValidationError = InferSchemaType<
    typeof responseValidationErrorSchema
>;

export const failedToParseRequestAsJSONErrorSchema = defineError(
    "FailedToParseRequestAsJSONError",
);
export const failedToParseRequestAsJSONError = createErrorFactory(
    failedToParseRequestAsJSONErrorSchema,
);
export type FailedToParseRequestAsJSONError = InferSchemaType<
    typeof failedToParseRequestAsJSONErrorSchema
>;

export const tooManyRequestsErrorSchema = defineError(
    "TooManyRequestsError",
);
export const tooManyRequestsError = createErrorFactory(
    tooManyRequestsErrorSchema,
);
export type TooManyRequestsError = InferSchemaType<
    typeof tooManyRequestsErrorSchema
>;

export const unauthorizedErrorSchema = defineError(
    "UnauthorizedError",
);
export const unauthorizedError = createErrorFactory(unauthorizedErrorSchema);
export type UnauthorizedError = InferSchemaType<typeof unauthorizedErrorSchema>;

export const invalidPasswordErrorSchema = defineError("InvalidPasswordError");
export const invalidPasswordError = createErrorFactory(
    invalidPasswordErrorSchema,
);
export type InvalidPasswordError = InferSchemaType<
    typeof invalidPasswordErrorSchema
>;

export const adminPasswordAlreadySetErrorSchema = defineError(
    "AdminPasswordAlreadySetError",
);
export const adminPasswordAlreadySetError = createErrorFactory(
    adminPasswordAlreadySetErrorSchema,
);
export type AdminPasswordAlreadySetError = InferSchemaType<
    typeof adminPasswordAlreadySetErrorSchema
>;

export const passwordsMustMatchErrorSchema = defineError(
    "PasswordsMustMatchError",
);
export const passwordsMustMatchError = createErrorFactory(
    passwordsMustMatchErrorSchema,
);
export type PasswordsMustMatchError = InferSchemaType<
    typeof passwordsMustMatchErrorSchema
>;

export const commandExecutionErrorSchema = defineError("CommandExecutionError");
export const commandExecutionError = createErrorFactory(
    commandExecutionErrorSchema,
);
export type CommandExecutionError = InferSchemaType<
    typeof commandExecutionErrorSchema
>;

export const deviceDoesNotExistErrorSchema = defineError(
    "DeviceDoesNotExistError",
);
export const deviceDoesNotExistError = createErrorFactory(
    deviceDoesNotExistErrorSchema,
);
export type DeviceDoesNotExistError = InferSchemaType<
    typeof deviceDoesNotExistErrorSchema
>;

export const deviceAlreadyBoundErrorSchema = defineError(
    "DeviceAlreadyBoundError",
);
export const deviceAlreadyBoundError = createErrorFactory(
    deviceAlreadyBoundErrorSchema,
);
export type DeviceAlreadyBoundError = InferSchemaType<
    typeof deviceAlreadyBoundErrorSchema
>;

export const deviceNotBoundErrorSchema = defineError("DeviceNotBoundError");
export const deviceNotBoundError = createErrorFactory(
    deviceNotBoundErrorSchema,
);
export type DeviceNotBoundError = InferSchemaType<
    typeof deviceNotBoundErrorSchema
>;

export const usbipUnknownErrorSchema = defineError("UsbipUnknownError");
export const usbipUnknownError = createErrorFactory(usbipUnknownErrorSchema);
export type UsbipUnknownError = InferSchemaType<typeof usbipUnknownErrorSchema>;

export const notFoundErrorSchema = defineError("NotFoundError");
export const notFoundError = createErrorFactory(notFoundErrorSchema);
export type NotFoundError = InferSchemaType<typeof notFoundErrorSchema>;

export const notAllowedErrorSchema = defineError("NotAllowedError");
export const notAllowedError = createErrorFactory(notAllowedErrorSchema);
export type NotAllowedError = InferSchemaType<typeof notAllowedErrorSchema>;

export const tooManyConnectionErrorSchema = defineError(
    "tooManyConnectionError",
);
export const tooManyConnectionError = createErrorFactory(
    tooManyConnectionErrorSchema,
);
export type TooManyConnectionError = InferSchemaType<
    typeof tooManyConnectionErrorSchema
>;
