const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
	const Drug = sequelize.define(
		"drug",
		{
			id: {
				type: DataTypes.INTEGER,
				autoIncrement: true,
				primaryKey: true,
			},
			creation: { type: DataTypes.DATE, allowNull: false },
			modified: { type: DataTypes.DATE, allowNull: false },
			modified_by: { type: DataTypes.INTEGER, allowNull: false },
			owner: { type: DataTypes.INTEGER, allowNull: false },

			// main
			display_name: { type: DataTypes.STRING(100), allowNull: false },
			generic_name: { type: DataTypes.STRING(100), allowNull: true },
			description: { type: DataTypes.TEXT, allowNull: true },
			image: { type: DataTypes.STRING, allowNull: true },

			composition: { type: DataTypes.TEXT, allowNull: true },
			benefits: { type: DataTypes.TEXT, allowNull: true },
			side_effects: { type: DataTypes.TEXT, allowNull: true },
			general_indication: { type: DataTypes.TEXT, allowNull: true },
			contraindication: { type: DataTypes.TEXT, allowNull: true },
			attention: { type: DataTypes.TEXT, allowNull: true },

			price: { type: DataTypes.INTEGER, allowNull: true },
			registration_number: { type: DataTypes.STRING(150), allowNull: true },

			active_ingredient: { type: DataTypes.TEXT, allowNull: true },
			used_by: { type: DataTypes.TEXT, allowNull: true },

			// fk
			// jenis obat
			// dosagetype_id: {
			//     type: DataTypes.INTEGER,
			//     allowNull: true,
			// },
			// satuan dosis
			dosageunit_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
			// bentuk dan sediaan obat
			dosageform_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
			// klasifikasi obat
			drugclassification_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
			// golongan obat
			druggroup_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
			// pabrik obat
			manufacturer_id: {
				type: DataTypes.INTEGER,
				allowNull: true,
			},
		},
		{
			tableName: "drugs",
			freezeTableName: true,
		}
	);

	/**
	 * Associates the Drug model with other models.
	 * @param {object} models - The models to associate with.
	 * @description
	 */
	Drug.associate = (models) => {};

	return Drug;
};
