'use strict';
import {orderStatus} from "../utils/constans/orders";

module.exports = (sequelize, DataTypes) => {
    const Orders = sequelize.define('Orders', {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.INTEGER
        },
        goodsId: {
            allowNull: false,
            type: DataTypes.INTEGER,
            onDelete: "CASCADE",
            references: {
                model: "GoodsAttributes",
                key: 'id'
            }
        },
        packageId: {
          allowNull: false,
          type: DataTypes.STRING,
        },
        userId: {
            allowNull: true,
            type: DataTypes.INTEGER,
            defaultValue: null
        },
        count: {
            allowNull: false,
            type: DataTypes.INTEGER
        },
        name: {
            allowNull: false,
            type: DataTypes.STRING
        },
        surname: {
          allowNull: false,
          type: DataTypes.STRING
        },
        phone: {
            allowNull: false,
            type: DataTypes.STRING
        },
        city: {
            allowNull: false,
            type: DataTypes.STRING
        },
        home: {
            allowNull: false,
            type: DataTypes.STRING
        },
        street: {
            allowNull: false,
            type: DataTypes.STRING
        },
        apartment: {
            allowNull: true,
            type: DataTypes.STRING
        },
        orderStatus: {
            allowNull: false,
            type: DataTypes.STRING,
            defaultValue: orderStatus.NOT_CONFIRMED
        }
    });

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

    return Orders;
};
