"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HasOneDirectiveDDBReferencesTransformer = void 0;
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
const ddb_references_generator_1 = require("../resolver/ddb-references-generator");
const resolvers_1 = require("../resolvers");
const utils_1 = require("../utils");
class HasOneDirectiveDDBReferencesTransformer {
    constructor() {
        this.dbType = graphql_transformer_core_1.DDB_DB_TYPE;
        this.prepare = (context, config) => {
            var _a, _b;
            const modelName = config.object.name.value;
            (0, resolvers_1.setFieldMappingResolverReference)(context, (_b = (_a = config.relatedType) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value, modelName, config.field.name.value, true);
            (0, utils_1.registerHasOneForeignKeyMappings)({
                transformParameters: context.transformParameters,
                resourceHelper: context.resourceHelper,
                thisTypeName: modelName,
                thisFieldName: config.field.name.value,
                relatedType: config.relatedType,
            });
        };
        this.transformSchema = (context, config) => {
            (0, utils_1.validateParentReferencesFields)(config, context);
        };
        this.generateResolvers = (context, config) => {
            (0, resolvers_1.updateTableForReferencesConnection)(config, context);
            new ddb_references_generator_1.DDBRelationalReferencesResolverGenerator().makeHasOneGetItemConnectionWithKeyResolver(config, context);
        };
        this.validate = (context, config) => {
            (0, utils_1.ensureReferencesArray)(config);
            config.referenceNodes = (0, utils_1.getReferencesNodes)(config, context);
        };
    }
}
exports.HasOneDirectiveDDBReferencesTransformer = HasOneDirectiveDDBReferencesTransformer;
//# sourceMappingURL=has-one-directive-ddb-references-transformer.js.map