'use strict';

var zodToJsonSchema = require('zod-to-json-schema');
var zodValidationError = require('zod-validation-error');
var errors = require('@backstage/errors');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

var zodToJsonSchema__default = /*#__PURE__*/_interopDefaultCompat(zodToJsonSchema);

function createSignInResolverFactory(options) {
  const { optionsSchema } = options;
  if (!optionsSchema) {
    return (resolverOptions) => {
      if (resolverOptions) {
        throw new errors.InputError("sign-in resolver does not accept options");
      }
      return options.create(void 0);
    };
  }
  const factory = (...[resolverOptions]) => {
    let parsedOptions;
    try {
      parsedOptions = optionsSchema.parse(resolverOptions);
    } catch (error) {
      throw new errors.InputError(
        `Invalid sign-in resolver options, ${zodValidationError.fromError(error)}`
      );
    }
    return options.create(parsedOptions);
  };
  factory.optionsJsonSchema = zodToJsonSchema__default.default(optionsSchema);
  return factory;
}

exports.createSignInResolverFactory = createSignInResolverFactory;
//# sourceMappingURL=createSignInResolverFactory.cjs.js.map
