export type TypeOrmAnalyticsSchemaErrorReason =
  | 'missing'
  | 'not_string'
  | 'empty_string'
  | 'not_number'
  | 'not_integer'
  | 'not_boolean'
  | 'not_date'
  | 'invalid_date'
  | 'invalid_enum_value'
  | 'not_object'
  | 'invalid_shape';

export class TypeOrmAnalyticsSchemaError extends Error {
  readonly entityName: string;
  readonly fieldName: string;
  readonly reason: TypeOrmAnalyticsSchemaErrorReason | (string & {});

  constructor(params: {
    entityName: string;
    fieldName: string;
    reason: TypeOrmAnalyticsSchemaError['reason'];
    message?: string;
  }) {
    const { entityName, fieldName, reason, message } = params;
    super(message);

    this.name = 'TypeOrmAnalyticsSchemaError';
    this.entityName = entityName;
    this.fieldName = fieldName;
    this.reason = reason;
  }
}