import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

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

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