const mongoose = require('mongoose');

const deploymentSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  sourceType: {
    type: String,
    enum: ['git', 'container'],
    required: true
  },
  gitUrl: String,
  containerImage: String,
  template: String,
  status: {
    type: String,
    enum: ['pending', 'deploying', 'running', 'failed', 'paused', 'error'],
    default: 'pending'
  },
  regions: [{
    type: String,
    required: true
  }],
  domain: {
    type: String,
    required: true
  },
  useWildcard: {
    type: Boolean,
    default: true
  },
  subdomain: String,
  env: [{
    key: String,
    value: String
  }],
  resources: {
    cpu: {
      type: Number,
      default: 0.5
    },
    memory: {
      type: String,
      default: '512Mi'
    }
  },
  createdBy: {
    type: String,
    required: true
  },
  createdAt: {
    type: Date,
    default: Date.now
  },
  error: String
});

module.exports = mongoose.model('Deployment', deploymentSchema); 