import { DataTypes, InferAttributes, InferCreationAttributes, Model, Sequelize } from "sequelize";

export type TabContextCreationAttributes = InferCreationAttributes<TabContextModel>;

export class TabContextModel extends Model<
  InferAttributes<TabContextModel>,
  InferCreationAttributes<TabContextModel>
> {
  // To avoid table creation
  /*static async sync(): Promise<any> {
      return Promise.resolve();
    }*/
  static associate(connection: Sequelize) {
    const { AuthUserModel } = connection.models;
  }

  declare id: string;
  declare tab_id: string;
  declare user_id: string;
}

export default (sequelize: Sequelize) => {
  TabContextModel.init(
    {
      id: {
        type: DataTypes.UUID,
        primaryKey: true,
      },
      user_id: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      tab_id: {
        type: DataTypes.UUID,
        allowNull: false,
      },
    },
    {
      sequelize,
      tableName: "user_tab_contexts",
      paranoid: true, // softs deletes
      timestamps: true,

      createdAt: "created_at",
      updatedAt: "updated_at",
      deletedAt: "deleted_at",

      indexes: [{ name: "tab_id_idx", fields: ["tab_id"], unique: true }],

      whereMergeStrategy: "and", // <- cómo tratar el merge de un scope

      defaultScope: {},

      scopes: {},
    }
  );
  return TabContextModel;
};
