import { pgTable, bigint, uuid, timestamp } from "drizzle-orm/pg-core";
import { portfolio } from "./portfolio";
import { organisation } from "./organisation";
import { InferModel } from "drizzle-orm";

export const portfolioOrganisation = pgTable("portfolio_organisation", {
  id: uuid("id").defaultRandom().primaryKey(),
  portfolioId: bigint("portfolio_id", { mode: "bigint" })
    .notNull()
    .references(() => portfolio.id, { onDelete: "cascade" })
    .unique(), // one organisation per portfolio
  organisationId: uuid("organisation_id")
    .notNull()
    .references(() => organisation.id, { onDelete: "cascade" }),
  createdAt: timestamp("created_at", { precision: 6, withTimezone: true })
    .defaultNow()
    .notNull(),
  updatedAt: timestamp("updated_at", { precision: 6, withTimezone: true })
    .defaultNow()
    .notNull(),
});

export type PortfolioOrganisation = InferModel<typeof portfolioOrganisation, "select">;
export type NewPortfolioOrganisation = InferModel<typeof portfolioOrganisation, "insert">;
