module.exports = (sequelize, DataTypes) => {
  const { UUID, UUIDV4, STRING, FLOAT, DATE, ENUM } = DataTypes;
  const ListingDiscounts = sequelize.define(
    'ListingDiscounts',
    {
      id: {
        type: UUID,
        defaultValue: UUIDV4,
        allowNull: false,
        primaryKey: true,
      },
      listing_id: {
        type: UUID,
        allowNull: true,
      },
      code: {
        type: STRING,
        allowNull: false,
      },
      percentage: {
        type: FLOAT,
        allowNull: false,
      },
      start_date: {
        type: DATE,
        allowNull: false,
      },
      end_date: {
        type: DATE,
        allowNull: false,
      },
      status: {
        type: ENUM('active', 'inactive'),
        defaultValue: 'active',
      },
    },
    {
      tableName: 'listing_discounts',
      timestamps: false,
    },
  );

  ListingDiscounts.associate = function (models) {
    ListingDiscounts.belongsTo(models.Listings, {
      foreignKey: 'listing_id',
      as: 'listing',
    });
  };

  return ListingDiscounts;
};
