const { UUID, UUIDV4, STRING, TEXT, DECIMAL, JSON: JSONTYPE, DATE, BOOLEAN } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
	const Activities = sequelize.define(
		'Activities',
		{
			id: {
				type: UUID,
				defaultValue: UUIDV4,
				allowNull: false,
				primaryKey: true,
			},
			type: {
				type: STRING,
				allowNull: false,
			},
			title: {
				type: STRING,
				allowNull: false,
			},
			description: {
				type: TEXT('long'),
				allowNull: false,
			},
			latitude: {
				type: DECIMAL(10, 8),
				allowNull: true,
			},
			longitude: {
				type: DECIMAL(11, 8),
				allowNull: true,
			},
			location: {
				type: STRING,
				allowNull: true,
			},
			about: {
				type: JSONTYPE,
				allowNull: true,
			},
			highlights: {
				type: TEXT('long'),
				allowNull: true,
			},
			full_description: {
				type: TEXT('long'),
				allowNull: true,
			},
			includes: {
				type: TEXT('long'),
				allowNull: true,
			},
			not_suitable_for: {
				type: TEXT('long'),
				allowNull: true,
			},
			important_information: {
				type: TEXT('long'),
				allowNull: true,
			},
			pickup_available: {
				type: BOOLEAN,
				allowNull: false,
				defaultValue: false,
			},
			duration: {
				type: STRING,
				allowNull: false,
			},
			price: {
				type: DECIMAL(10, 2),
				allowNull: false,
				defaultValue: 0.0,
			},
			old_price: {
				type: DECIMAL(10, 2),
				allowNull: true,
				defaultValue: null,
			},
			price_type: {
				type: DataTypes.ENUM('per person', 'fixed'),
				allowNull: true,
				defaultValue: 'per person',
			},
			createdAt: {
				type: DATE,
				allowNull: false,
				defaultValue: DataTypes.NOW,
			},
		},
		{
			tableName: 'activities',
			timestamps: false,
		},
	);

	Activities.associate = (models) => {
		Activities.hasMany(models.ActivityImages, { as: 'images', foreignKey: 'activity_id' });
		Activities.hasMany(models.ActivityLikes, { as: 'likes', foreignKey: 'activity_id' });
		Activities.hasMany(models.ActivityReviews, { as: 'reviews', foreignKey: 'activity_id' });
		Activities.hasMany(models.ActivityReviews, { as: 'highlightedReviews', foreignKey: 'activity_id' });
		Activities.hasOne(models.ActivityReviews, { as: 'review', foreignKey: 'activity_id' });
		Activities.hasMany(models.ActivityItineraries, { as: 'itineraries', foreignKey: 'activity_id' });
	};

	return Activities;
};
