const {DataTypes} = require("sequelize")

module.exports = (sequelize) => {
  const OptionChain = sequelize.define(
    "OptionChain",
    {
      symbol: { type: DataTypes.STRING, allowNull: false },
      expiry: { type: DataTypes.STRING, allowNull: false },
      strike: { type: DataTypes.DECIMAL(18, 4), allowNull: false },

      callBid: { type: DataTypes.DECIMAL(18, 4), allowNull: false, defaultValue: 0 },
      callAsk: { type: DataTypes.DECIMAL(18, 4), allowNull: false, defaultValue: 0 },

      putBid: { type: DataTypes.DECIMAL(18, 4), allowNull: false, defaultValue: 0 },
      putAsk: { type: DataTypes.DECIMAL(18, 4), allowNull: false, defaultValue: 0 },

      callIv: { type: DataTypes.DECIMAL(18, 4), allowNull: true, defaultValue: 0 },
      putIv: { type: DataTypes.DECIMAL(18, 4), allowNull: true, defaultValue: 0 },

      openInterest: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0 },
      volume: { type: DataTypes.INTEGER, allowNull: true, defaultValue: 0 },
    },
    {
      tableName: "option_chain",
      timestamps: true,
      underscored: true,
      indexes: [
        {
          fields: ["symbol", "expiry", "strike"],
        },
      ],
    }
  );

  return OptionChain;
};