const { UUID, UUIDV4, STRING, INTEGER, TEXT } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
	const ActivityReviews = sequelize.define(
		'ActivityReviews',
		{
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			activity_id: {
				type: UUID,
				allowNull: false,
			},
			member_id: {
				type: UUID,
				allowNull: false,
			},
			guide_rating: {
				type: INTEGER,
				allowNull: false,
			},
			transportation_rating: {
				type: INTEGER,
				allowNull: true,
			},
			value_for_money_rating: {
				type: INTEGER,
				allowNull: true,
			},
			review: {
				type: TEXT,
				allowNull: true,
			},
			is_highlighted: {
				type: DataTypes.BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
			is_anonymous: {
				type: DataTypes.BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
			booking_id: {
				type: DataTypes.UUID,
				allowNull: true,
				onDelete: 'CASCADE',
			},
			createdAt: {
				type: DataTypes.DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
		},
		{
			tableName: 'activity_reviews',
			timestamps: false,
		},
	);

	ActivityReviews.associate = (models) => {
		ActivityReviews.hasMany(models.ActivityReviewImages, {
			foreignKey: 'activity_review_id',
			as: 'images',
		});
		ActivityReviews.belongsTo(models.Members, {
			foreignKey: 'member_id',
			as: 'member',
		});
	};

	return ActivityReviews;
};
