// falukant/predefine/political_office_benefit.js
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
import PoliticalOfficeBenefitType from '../type/political_office_benefit_type.js';

class PoliticalOfficeBenefit extends Model {}

PoliticalOfficeBenefit.init({
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true},
  politicalOfficeId: { 
    type: DataTypes.INTEGER,
    allowNull: false},
  benefitTypeId: {
    type: DataTypes.INTEGER,
    allowNull: false},
  value: {
    type: DataTypes.JSONB,
    allowNull: false}}, {
  sequelize, 
  modelName: 'PoliticalOfficeBenefit',
  tableName: 'political_office_benefit',
  schema: 'falukant_predefine',
  timestamps: false,
  underscored: true});

// Association
PoliticalOfficeBenefit.belongsTo(PoliticalOfficeBenefitType, {
  foreignKey: 'benefit_type_id',
  as: 'benefitType'
});
PoliticalOfficeBenefitType.hasMany(PoliticalOfficeBenefit, {
  foreignKey: 'benefit_type_id',
  as: 'benefits'
});

export default PoliticalOfficeBenefit;
