module.exports = (sequelize, DataTypes) => {
	const ProductCarts = sequelize.define(
		'ProductCarts',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			product_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'products',
					key: 'id',
				},
			},
			member_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'members',
					key: 'id',
				},
			},
			color: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			size: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			quantity: {
				type: DataTypes.INTEGER,
				allowNull: false,
				defaultValue: 1,
			},
			updatedAt: {
				type: DataTypes.DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
		},
		{
			tableName: 'product_carts',
			timestamps: false,
		},
	);

	ProductCarts.associate = (models) => {
		ProductCarts.belongsTo(models.Products, {
			foreignKey: 'product_id',
			as: 'product',
		});
		ProductCarts.belongsTo(models.Members, {
			foreignKey: 'member_id',
			as: 'member',
		});
	};

	return ProductCarts;
};
