// falukant/data/vote.js
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';

class Vote extends Model {}

Vote.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true},
    electionId: {
      type: DataTypes.INTEGER,
      allowNull: false},
    candidateId: {
      type: DataTypes.INTEGER,
      allowNull: false},
    timestamp: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW},
    falukantUserId: {
      type: DataTypes.INTEGER,
      allowNull: false}},
  {
    sequelize,
    modelName: 'Vote',
    tableName: 'vote',
    schema: 'falukant_data',
    timestamps: true,
    underscored: true,
    indexes: [
      {
        unique: true,
        fields: ['election_id', 'candidate_id']},
    ]}
);

export default Vote;
