import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

export class InvalidSeasonStatusSchemaError extends TypeOrmPersistenceSchemaError {
  override readonly name: string = 'InvalidSeasonStatusSchemaError';

  constructor(params: InvalidSeasonStatusSchemaErrorParams);
  constructor(message: string);
  constructor(paramsOrMessage: InvalidSeasonStatusSchemaErrorParams | string) {
    if (typeof paramsOrMessage === 'string') {
      super({
        entityName: 'Season',
        fieldName: 'status',
        reason: 'invalid_shape',
        message: paramsOrMessage,
      });
      return;
    }

    super({
      entityName: 'Season',
      fieldName: paramsOrMessage.fieldName,
      reason: paramsOrMessage.reason,
      ...(paramsOrMessage.message ? { message: paramsOrMessage.message } : {}),
    });
  }
}