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

const TeamPermissions = sequelize.define('TeamPermissions', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  role: {
    type: DataTypes.ENUM('admin', 'ui_team', 'ux_team', 'qa_team'),
    allowNull: false
  },
  permission: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: 'Human readable permission name, e.g. "sync_figma"'
  },
  resource: {
    type: DataTypes.STRING,
    allowNull: false
  },
  action: {
    type: DataTypes.ENUM('create', 'read', 'update', 'delete'),
    allowNull: false
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'team_permissions',
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['role', 'resource', 'action'],
      name: 'unique_role_resource_action'
    }
  ]
});

export default TeamPermissions;
