module.exports = (sequelize, DataTypes) => {
	const Products = sequelize.define(
		'Products',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			name: {
				type: DataTypes.STRING,
				allowNull: false,
			},
			description: {
				type: DataTypes.TEXT('long'),
				allowNull: true,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
			},
			colors: {
				type: DataTypes.JSON,
				allowNull: true,
			},
			sizes: {
				type: DataTypes.JSON,
				allowNull: true,
			},
			createdAt: {
				type: DataTypes.DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
		},
		{
			tableName: 'products',
			timestamps: false,
		},
	);

	Products.associate = (models) => {
		Products.hasMany(models.ProductImages, {
			foreignKey: 'product_id',
			as: 'images',
		});
		Products.hasMany(models.ProductCarts, {
			foreignKey: 'product_id',
			as: 'carts',
		});
		Products.hasMany(models.ProductDetails, {
			foreignKey: 'product_id',
			as: 'details',
		});
	};

	return Products;
};
