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

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

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