import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../../../utils/sequelize.js';
import RegionType from '../type/region.js';

class RegionData extends Model { }

RegionData.init({
    name: {
        type: DataTypes.STRING,
        allowNull: false},
    regionTypeId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: RegionType,
            key: 'id',
            schema: 'falukant_type'
        }
    },
    parentId: {
        type: DataTypes.INTEGER,
        allowNull: true,
        references: {
            model: 'region',
            key: 'id',
            schema: 'falukant_data'}
    },
    map: {
        type: DataTypes.JSONB,
        allowNull: true,
        defaultValue: {}
    }
}, {
    sequelize,
    modelName: 'RegionData',
    tableName: 'region',
    schema: 'falukant_data',
    timestamps: false,
    underscored: true});

export default RegionData;
