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

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

  constructor(params: {
    entityName: string;
    fieldName: string;
    reason: TypeOrmPaymentsSchemaError['reason'];
    message?: string;
  }) {
    const message =
      params.message ?? `Invalid persisted ${params.entityName}.${params.fieldName}: ${params.reason}`;
    super(message);
    this.name = 'TypeOrmPaymentsSchemaError';
    this.entityName = params.entityName;
    this.fieldName = params.fieldName;
    this.reason = params.reason;
  }
}