import { Model, DataTypes, Sequelize } from 'sequelize'; export interface StateAttributes { id: string; stateName: string; zoneId: string; isActive: boolean; } export interface StateInstance extends Model, StateAttributes { } export default (sequelize: Sequelize) => { const State = sequelize.define('State', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, stateName: { type: DataTypes.STRING, unique: true, allowNull: false }, zoneId: { type: DataTypes.UUID, allowNull: false, references: { model: 'zones', key: 'id' } }, isActive: { type: DataTypes.BOOLEAN, defaultValue: true } }, { tableName: 'states', timestamps: true }); (State as any).associate = (models: any) => { State.belongsTo(models.Zone, { foreignKey: 'zoneId', as: 'zone' }); State.hasMany(models.District, { foreignKey: 'stateId', as: 'districts' }); State.hasMany(models.Region, { foreignKey: 'stateId', as: 'regions' }); }; return State; };