db = db.getSiblingDB('pki_db');

// Create collections
db.createCollection('cas');
db.createCollection('subcas');
db.createCollection('certificates');

// Create indexes
db.cas.createIndex({ name: 1 }, { unique: true });
db.cas.createIndex({ common_name: 1 }, { unique: true });

db.subcas.createIndex({ name: 1 }, { unique: true });
db.subcas.createIndex({ common_name: 1 }, { unique: true });
db.subcas.createIndex({ parent_ca_id: 1 });

db.certificates.createIndex({ common_name: 1 });
db.certificates.createIndex({ issuer_ca_id: 1 });
db.certificates.createIndex({ serial_number: 1 }, { unique: true });
db.certificates.createIndex({ revoked: 1 });

print('PKI database initialized successfully');