// models/store.js
'use strict';
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class Store extends Model {
    static associate(models) {
      Store.hasMany(models.User, { foreignKey: 'storeId', as: 'users' });
      Store.hasMany(models.Register, { foreignKey: 'storeId', as: 'registers' });
      Store.hasMany(models.Transaction, { foreignKey: 'storeId', as: 'transactions' });
      Store.hasMany(models.Inventory, { foreignKey: 'storeId', as: 'inventory' });
      Store.hasMany(models.PurchaseOrder, { foreignKey: 'storeId', as: 'purchaseOrders' });
      Store.hasMany(models.DailySales, { foreignKey: 'storeId', as: 'dailySales' });
      Store.hasMany(models.StockMovement, { foreignKey: 'storeId', as: 'stockmovements' });
      Store.hasMany(models.Return, { foreignKey: 'storeId', as: 'return' });
      Store.hasMany(models.CashDrawerSession, { foreignKey: 'storeId', as: 'drawerSession' });
      Store.hasMany(models.CashDrawerActivity, { foreignKey: 'storeId', as: 'cashDrawers' });
      
      

    }
  }
  Store.init({
    name: DataTypes.STRING,
    code: { type: DataTypes.STRING, unique: true },
    address: DataTypes.TEXT,
    city: DataTypes.STRING,
    state: DataTypes.STRING,
    country: DataTypes.STRING,
    postalCode: DataTypes.STRING,
    phone: DataTypes.STRING,
    email: DataTypes.STRING,
    taxId: DataTypes.STRING,
    currency: { type: DataTypes.STRING, defaultValue: 'USD' },
    timezone: { type: DataTypes.STRING, defaultValue: 'UTC' },
    isActive: { type: DataTypes.BOOLEAN, defaultValue: true }
  }, {
    sequelize,
    modelName: 'Store',
    tableName: 'stores',
    timestamps: true
  });
  return Store;
};
