const { Sequelize, DataTypes } = require('sequelize');

const { DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD } = process.env;

const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASSWORD, {
  host: DB_HOST,
  port: DB_PORT,
  dialect: 'mysql',
});

const Product = sequelize.define(
  'Products',
  {
    pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
    cid: { type: DataTypes.INTEGER, allowNull: false },
    name: { type: DataTypes.STRING, allowNull: false },
    description: { type: DataTypes.STRING, allowNull: false },
    price: { type: DataTypes.DECIMAL, allowNull: false },
    product_image: { type: DataTypes.STRING, allowNull: true, defaultValue: '' },
  },
  { timestamps: false },
);

export { Product, sequelize };
