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

const Team = sequelize.define('Team', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING(255),
    allowNull: false,
    validate: { len: [2, 255] }
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  ownerId: {
    type: DataTypes.UUID,
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  settings: {
    type: DataTypes.JSON,
    defaultValue: {
      color: '#3498db',
      icon: 'users',
      visibility: 'private',
      allowPublicProjects: false
    }
  },
  isActive: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    index: true
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {
      createdByAdmin: false,
      department: null,
      costCenter: null
    }
  }
}, {
  tableName: 'teams',
  timestamps: true
});

export default Team;
