'use strict';

module.exports = (sequelize, DataTypes) => {
    const GoodsAttributes = sequelize.define('GoodsAttributes', {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.INTEGER
        },
        imgUrlArray: {
            allowNull: false,
            type: DataTypes.ARRAY(DataTypes.TEXT)
        },
        goodsId: {
            allowNull: false,
            type: DataTypes.INTEGER,
            onDelete: 'CASCADE',
            references: {
                model: 'Goods',
                key: 'id'
            }
        },
        nameAttribute: {
            allowNull: false,
            type: DataTypes.STRING
        },
        valueAttribute: {
            allowNull: false,
            type: DataTypes.STRING
        },
        price: {
            allowNull: false,
            type: DataTypes.FLOAT
        },
    });

    GoodsAttributes.associate = function (models) {
        GoodsAttributes.belongsTo(models.Goods, {foreignKey: 'goodsId', sourceKey: 'id'});
        GoodsAttributes.belongsTo(models.GoodsFavourites, {foreignKey: 'goodsId', sourceKey: 'id'});
        GoodsAttributes.belongsTo(models.Orders, {foreignKey: 'goodsId', sourceKey: 'id'});
    };

    return GoodsAttributes;
};
