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

const Project = sequelize.define('Project', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  key: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    validate: {
      is: /^[A-Z0-9]+$/
    }
  },
  userId: {
    type: DataTypes.UUID,
    allowNull: false,
    references: {
      model: 'Users',
      key: 'id'
    }
  },
  figmaFileKey: {
    type: DataTypes.STRING,
    allowNull: true
  },
  jiraProjectKey: {
    type: DataTypes.STRING,
    allowNull: true
  },
  storybookUrl: {
    type: DataTypes.STRING,
    allowNull: true,
    validate: { isUrl: true }
  },
  status: {
    type: DataTypes.ENUM('active', 'archived', 'draft'),
    defaultValue: 'draft'
  },
  settings: {
    type: DataTypes.JSON,
    defaultValue: {
      tokenNamespace: 'design',
      colorFormat: 'hex',
      spacingUnit: 'px'
    }
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  timestamps: true
});

export default Project;
