import { relations } from 'drizzle-orm';
import { organizations } from './organizations';
import { projects } from './projects';
import { apiKeys } from './apiKeys';

// Export all tables
export * from './organizations';
export * from './projects';
export * from './apiKeys';

// Define relations
export const organizationsRelations = relations(organizations, ({ many }) => ({
  projects: many(projects),
  apiKeys: many(apiKeys),
}));

export const projectsRelations = relations(projects, ({ one, many }) => ({
  organization: one(organizations, {
    fields: [projects.organizationId],
    references: [organizations.id],
  }),
  apiKeys: many(apiKeys),
}));

export const apiKeysRelations = relations(apiKeys, ({ one }) => ({
  organization: one(organizations, {
    fields: [apiKeys.organizationId],
    references: [organizations.id],
  }),
  project: one(projects, {
    fields: [apiKeys.projectId],
    references: [projects.id],
  }),
}));
