'use strict'; module.exports = (sequelize, DataTypes) => { const Organization = sequelize.define('Organization', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, name: { type: DataTypes.STRING, allowNull: false }, slug: { type: DataTypes.STRING, unique: true }, timezone: { type: DataTypes.STRING, defaultValue: 'UTC' }, features: { type: DataTypes.TEXT, defaultValue: '[]', get() { try { return JSON.parse(this.getDataValue('features') || '[]'); } catch { return []; } }, set(v) { this.setDataValue('features', JSON.stringify(v)); }, }, isActive: { type: DataTypes.BOOLEAN, defaultValue: true }, licenseOwner: { type: DataTypes.STRING }, licenseEmail: { type: DataTypes.STRING }, }); Organization.beforeCreate(org => { if (!org.slug) { org.slug = org.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''); } }); const Branding = sequelize.define('Branding', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, organizationId: { type: DataTypes.INTEGER, allowNull: false, unique: true }, appName: { type: DataTypes.STRING, defaultValue: 'VitFit' }, logoPath: { type: DataTypes.STRING }, primaryColor: { type: DataTypes.STRING, defaultValue: '#00FF88' }, secondaryColor: { type: DataTypes.STRING, defaultValue: '#4488FF' }, workColor: { type: DataTypes.STRING, defaultValue: '#00FF88' }, restColor: { type: DataTypes.STRING, defaultValue: '#4488FF' }, moveColor: { type: DataTypes.STRING, defaultValue: '#FF4444' }, }); Organization.associate = (models) => { Organization.hasOne(models.Branding, { foreignKey: 'organizationId' }); }; return { Organization, Branding }; };