module.exports = (sequelize, DataTypes) => {
	const ProductDetails = sequelize.define(
		'ProductDetails',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			product_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'products',
					key: 'id',
				},
			},
			color: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			size: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			stock: {
				type: DataTypes.INTEGER,
				allowNull: false,
				defaultValue: 0,
			},
		},
		{
			tableName: 'product_details',
			timestamps: false,
		},
	);

	ProductDetails.associate = (models) => {
		ProductDetails.belongsTo(models.Products, {
			foreignKey: 'product_id',
			as: 'product',
		});
	};

	return ProductDetails;
};
