import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';

class TownProductWorth extends Model { }

TownProductWorth.init({
    productId: {
        type: DataTypes.INTEGER,
        allowNull: false},
    regionId: {
        type: DataTypes.INTEGER,
        allowNull: false},
    worthPercent: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0}
}, {
    sequelize,
    modelName: 'TownProductWorth',
    tableName: 'town_product_worth',
    schema: 'falukant_data',
    timestamps: false,
    underscored: true,
    hooks: {
        beforeCreate: (worthPercent) => {
            worthPercent.worthPercent = Math.floor(Math.random() * 20) + 40;
        }
    }
});

export default TownProductWorth;
