import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

type InvalidStandingSchemaErrorParams = {
  fieldName: string;
  reason: TypeOrmPersistenceSchemaError['reason'];
  message?: string;
};

export class InvalidStandingSchemaError extends TypeOrmPersistenceSchemaError {
  constructor(params: InvalidStandingSchemaErrorParams);
  constructor(message: string);
  constructor(paramsOrMessage: InvalidStandingSchemaErrorParams | string) {
    const params =
      typeof paramsOrMessage === 'string'
        ? {
            entityName: 'Standing',
            fieldName: 'unknown',
            reason: 'invalid_shape' as const,
            message: paramsOrMessage,
          }
        : {
            entityName: 'Standing',
            fieldName: paramsOrMessage.fieldName,
            reason: paramsOrMessage.reason,
            ...(paramsOrMessage.message ? { message: paramsOrMessage.message } : {}),
          };

    super(params);
    this.name = 'InvalidStandingSchemaError';
  }
}