import type * as Schema from './schema';

// ── Plugin tables come from their OWN schema, not from the aggregator ──
//
// `./schema` is drizzle-kit's view of the database — what `bun db:push` reads — so a
// table that belongs to a plugin is commented out there and genuinely absent from the
// live database. That is the point of the core/plugin split.
//
// Inferring a TYPE from it, though, has nothing to do with whether the table exists:
// these describe rows that the plugin's own code passes around, and that code compiles
// whether or not the plugin is installed. Reading them off the aggregator coupled the
// two, so commenting a plugin out of `schema.ts` broke the build of code that was
// already unreachable.
//
// Same move the query modules made when the split landed — import the feature's schema
// directly — which is what lets a table leave the aggregator without breaking anything.
import type * as EmailSchema from './email/schema';
import type * as NotifySchema from './notify/schema';

// ── Auth ──

export type UserSelect = typeof Schema.users.$inferSelect;
export type UserInsert = typeof Schema.users.$inferInsert;
export type User = UserSelect & {
  passkeys: PasskeySelect[];
};

export type PasskeySelect = typeof Schema.passkeys.$inferSelect;
export type PasskeyInsert = typeof Schema.passkeys.$inferInsert;
export type Passkey = PasskeySelect & {
  user: UserSelect;
};

export type PasskeyChallengeSelect = typeof Schema.passkeyChallenges.$inferSelect;
export type PasskeyChallengeInsert = typeof Schema.passkeyChallenges.$inferInsert;

export type TokenBlacklistSelect = typeof Schema.tokenBlacklist.$inferSelect;
export type TokenBlacklistInsert = typeof Schema.tokenBlacklist.$inferInsert;

// ── User Data ──

export type UserSettingsSelect = typeof Schema.userSettings.$inferSelect;
export type UserSettingsInsert = typeof Schema.userSettings.$inferInsert;

export type UserStateSelect = typeof Schema.userState.$inferSelect;
export type UserStateInsert = typeof Schema.userState.$inferInsert;

export type UserIntegrationSelect = typeof Schema.userIntegrations.$inferSelect;
export type UserIntegrationInsert = typeof Schema.userIntegrations.$inferInsert;

export type DockConfigSelect = typeof Schema.dockConfigs.$inferSelect;
export type DockConfigInsert = typeof Schema.dockConfigs.$inferInsert;

// ── Saved Sessions ──

// ── Dashboards ──

export type DashboardSelect = typeof Schema.dashboards.$inferSelect;
export type DashboardInsert = typeof Schema.dashboards.$inferInsert;

export type ScreenSelect = typeof Schema.screens.$inferSelect;
export type ScreenInsert = typeof Schema.screens.$inferInsert;

// ── Email ──

export type EmailAccountSelect = typeof EmailSchema.emailAccounts.$inferSelect;
export type EmailAccountInsert = typeof EmailSchema.emailAccounts.$inferInsert;

// ── Server ──

export type ServerConfigSelect = typeof Schema.serverConfig.$inferSelect;
export type ServerConfigInsert = typeof Schema.serverConfig.$inferInsert;

export type ServerIntegrationSelect = typeof Schema.serverIntegrations.$inferSelect;
export type ServerIntegrationInsert = typeof Schema.serverIntegrations.$inferInsert;

// ── Pipeline Jobs ──

export type PipelineJobSelect = typeof Schema.pipelineJobs.$inferSelect;
export type PipelineJobInsert = typeof Schema.pipelineJobs.$inferInsert;

// Notifications
export type PushDeviceSelect = typeof NotifySchema.pushDevices.$inferSelect;
export type PushDeviceInsert = typeof NotifySchema.pushDevices.$inferInsert;

// ── API keys ──

export type ApiKeySelect = typeof Schema.apiKeys.$inferSelect;
export type ApiKeyInsert = typeof Schema.apiKeys.$inferInsert;
