import { relations } from "drizzle-orm/relations";
import { users, explorerContent, userSessions, usersData, userPermissions } from "./schema";

export const explorerContentRelations = relations(explorerContent, ({one}) => ({
	user: one(users, {
		fields: [explorerContent.owner],
		references: [users.id]
	}),
}));

export const usersRelations = relations(users, ({many}) => ({
	explorerContents: many(explorerContent),
	userSessions: many(userSessions),
	usersData: many(usersData),
	userPermissions: many(userPermissions),
}));

export const userSessionsRelations = relations(userSessions, ({one}) => ({
	user: one(users, {
		fields: [userSessions.userId],
		references: [users.id]
	}),
}));

export const usersDataRelations = relations(usersData, ({one}) => ({
	user: one(users, {
		fields: [usersData.id],
		references: [users.id]
	}),
}));

export const userPermissionsRelations = relations(userPermissions, ({one}) => ({
	user: one(users, {
		fields: [userPermissions.id],
		references: [users.id]
	}),
}));