"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MySQLSchema = void 0;
const HotDBSchema_1 = require("../HotDBSchema");
/**
 * The MySQL schema.
 */
class MySQLSchema extends HotDBSchema_1.HotDBSchema {
    constructor(name) {
        super(name);
        this.tables = {};
    }
    /**
     * Add a table to this schema.
     */
    addTable(table) {
        this.tables[table.name] = table;
    }
    /**
     * Add a field to a table.
     */
    addFieldToTable(tableName, field) {
        if (this.tables[tableName] == null)
            throw new Error(`Table ${tableName} does not exist!`);
        this.tables[tableName].fields.push(field);
    }
    /**
     * Add a field to a table.
     */
    addFieldsToTable(tableName, fields) {
        if (this.tables[tableName] == null)
            throw new Error(`Table ${tableName} does not exist!`);
        for (let iIdx = 0; iIdx < fields.length; iIdx++) {
            let field = fields[iIdx];
            this.tables[tableName].fields.push(field);
        }
    }
    /**
     * Generate a table's structure. If type is set to modify, you must pass a db with an
     * active connection.
     */
    generateTableStructure(tableName_1) {
        return __awaiter(this, arguments, void 0, function* (tableName, type = HotDBSchema_1.HotDBGenerationType.Create, db = null) {
            if (this.tables[tableName] == null)
                throw new Error(`Unable to generate table structure for ${tableName}. Table doesn't exist.`);
            let table = this.tables[tableName];
            let generatedStructure = yield table.generate(type, db);
            return (generatedStructure);
        });
    }
    /**
     * Generate the entire db structure. If type is set to modify, you must pass a db with an
     * active connection.
     */
    generateStructure() {
        return __awaiter(this, arguments, void 0, function* (type = HotDBSchema_1.HotDBGenerationType.Create, db = null) {
            let result = [];
            for (let key in this.tables) {
                let generatedStructure = yield this.generateTableStructure(key, type, db);
                result.push(generatedStructure);
            }
            return (result);
        });
    }
}
exports.MySQLSchema = MySQLSchema;
//# sourceMappingURL=MySQLSchema.js.map