import { DataTypes } from 'sequelize';
import sequelize from '../config/config.js';

const DashboardVisibility = sequelize.define('DashboardVisibility', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  treelogy_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'treelogy',
      key: 'treelogy_id'
    }
  },
  card_id: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: 'Unique identifier for dashboard card/chart (e.g., total_trees, species_count)'
  },
  card_name: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: 'Display name for the card/chart'
  },
  card_type: {
    type: DataTypes.ENUM('card', 'chart'),
    allowNull: false,
    defaultValue: 'card'
  },
  is_visible: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: 'Whether this card/chart is visible to the client'
  },
  display_order: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: 'Order in which cards/charts appear on dashboard'
  },
  created_at: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  },
  updated_at: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'dashboard_visibility',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  indexes: [
    {
      unique: true,
      fields: ['treelogy_id', 'card_id']
    }
  ]
});

export default DashboardVisibility;
