module.exports = (sequelize, DataTypes) => {
	const ProductPurchaseItems = sequelize.define(
		'ProductPurchaseItems',
		{
			id: {
				type: DataTypes.UUID,
				defaultValue: DataTypes.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			purchase_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'product_purchases',
					key: 'id',
				},
			},
			product_id: {
				type: DataTypes.UUID,
				allowNull: false,
				references: {
					model: 'products',
					key: 'id',
				},
			},
			quantity: {
				type: DataTypes.INTEGER,
				allowNull: false,
				defaultValue: 1,
			},
			price: {
				type: DataTypes.DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			color: {
				type: DataTypes.STRING,
				allowNull: true,
			},
			size: {
				type: DataTypes.STRING,
				allowNull: true,
			},
		},
		{
			tableName: 'product_purchase_items',
			timestamps: false,
		},
	);

	ProductPurchaseItems.associate = (models) => {
		ProductPurchaseItems.belongsTo(models.ProductPurchases, {
			foreignKey: 'purchase_id',
			as: 'purchase',
		});
		ProductPurchaseItems.belongsTo(models.Products, {
			foreignKey: 'product_id',
			as: 'product',
		});
	};

	return ProductPurchaseItems;
};
