"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BelongsToDirectiveSQLTransformer = void 0;
const graphql_transformer_core_1 = require("@aws-amplify/graphql-transformer-core");
const generator_factory_1 = require("../resolver/generator-factory");
const resolvers_1 = require("../resolvers");
const utils_1 = require("../utils");
class BelongsToDirectiveSQLTransformer {
    constructor() {
        this.dbType = graphql_transformer_core_1.POSTGRES_DB_TYPE || graphql_transformer_core_1.MYSQL_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);
        };
        this.transformSchema = (context, config) => {
            (0, utils_1.validateChildReferencesFields)(config, context);
        };
        this.generateResolvers = (context, config) => {
            const generator = (0, generator_factory_1.getGenerator)(this.dbType);
            generator.makeBelongsToGetItemConnectionWithKeyResolver(config, context);
        };
        this.validate = (context, config) => {
            (0, utils_1.ensureReferencesArray)(config);
            config.referenceNodes = (0, utils_1.getBelongsToReferencesNodes)(config, context);
        };
    }
}
exports.BelongsToDirectiveSQLTransformer = BelongsToDirectiveSQLTransformer;
//# sourceMappingURL=belongs-to-directive-sql-transformer.js.map