import type { Kysely } from "kysely";
import { sql } from "kysely";

export async function up(db: Kysely<any>): Promise<void> {
  await db.schema
    .createTable("point_transactions")
    .ifNotExists()
    .addColumn("id", "uuid", (col) =>
      col.primaryKey().defaultTo(sql`gen_random_uuid()`),
    )
    .addColumn("source_holding_account", "text", (col) => col.notNull())
    .addColumn("target_manager_id", "uuid", (col) => col.notNull())
    .addColumn("points", "integer", (col) => col.notNull())
    .addColumn("initiator_id", "uuid", (col) => col.notNull())
    .addColumn("notes", "text")
    .addColumn("viewpoint_ref_id", "text")
    .addColumn("status", "text", (col) => col.notNull())
    .addColumn("created_at", "timestamptz", (col) =>
      col.notNull().defaultTo(sql`NOW()`),
    )
    .addColumn("updated_at", "timestamptz")
    .execute();
}

export async function down(db: Kysely<any>): Promise<void> {
  await db.schema.dropTable("point_transactions").ifExists().execute();
}
