import type { ColumnType, Insertable, Selectable, Updateable } from "kysely"
import type { ActionRunsId } from "./ActionRuns"
import type { ApiAccessTokensId } from "./ApiAccessTokens"
import type { OperationType } from "./OperationType"
import type { PubValues } from "./PubValues"
import type { UsersId } from "./Users"

import { z } from "zod"

import { actionRunsIdSchema } from "./ActionRuns"
import { apiAccessTokensIdSchema } from "./ApiAccessTokens"
import { operationTypeSchema } from "./OperationType"
import { usersIdSchema } from "./Users"

// @generated
// This file is automatically generated by Kanel. Do not modify manually.

/** Identifier type for public.pub_values_history */
export type PubValuesHistoryId = string & { __brand: "PubValuesHistoryId" }

/** Represents the table public.pub_values_history */
export interface PubValuesHistoryTable {
	id: ColumnType<PubValuesHistoryId, PubValuesHistoryId | undefined, PubValuesHistoryId>

	createdAt: ColumnType<Date, Date | string | undefined, Date | string>

	operationType: ColumnType<OperationType, OperationType, OperationType>

	oldRowData: ColumnType<PubValues, string | null, string | null>

	newRowData: ColumnType<PubValues, string | null, string | null>

	pubValueId: ColumnType<string | null, string | null, string | null>

	userId: ColumnType<UsersId | null, UsersId | null, UsersId | null>

	apiAccessTokenId: ColumnType<
		ApiAccessTokensId | null,
		ApiAccessTokensId | null,
		ApiAccessTokensId | null
	>

	actionRunId: ColumnType<ActionRunsId | null, ActionRunsId | null, ActionRunsId | null>

	other: ColumnType<string | null, string | null, string | null>
}

export type PubValuesHistory = Selectable<PubValuesHistoryTable>

export type NewPubValuesHistory = Insertable<PubValuesHistoryTable>

export type PubValuesHistoryUpdate = Updateable<PubValuesHistoryTable>

export const pubValuesHistoryIdSchema = z.string().uuid() as unknown as z.Schema<PubValuesHistoryId>

export const pubValuesHistorySchema = z.object({
	id: pubValuesHistoryIdSchema,
	createdAt: z.date(),
	operationType: operationTypeSchema,
	oldRowData: z.unknown().nullable(),
	newRowData: z.unknown().nullable(),
	pubValueId: z.string().nullable(),
	userId: usersIdSchema.nullable(),
	apiAccessTokenId: apiAccessTokensIdSchema.nullable(),
	actionRunId: actionRunsIdSchema.nullable(),
	other: z.string().nullable(),
})

export const pubValuesHistoryInitializerSchema = z.object({
	id: pubValuesHistoryIdSchema.optional(),
	createdAt: z.date().optional(),
	operationType: operationTypeSchema,
	oldRowData: z.unknown().optional().nullable(),
	newRowData: z.unknown().optional().nullable(),
	pubValueId: z.string().optional().nullable(),
	userId: usersIdSchema.optional().nullable(),
	apiAccessTokenId: apiAccessTokensIdSchema.optional().nullable(),
	actionRunId: actionRunsIdSchema.optional().nullable(),
	other: z.string().optional().nullable(),
})

export const pubValuesHistoryMutatorSchema = z.object({
	id: pubValuesHistoryIdSchema.optional(),
	createdAt: z.date().optional(),
	operationType: operationTypeSchema.optional(),
	oldRowData: z.unknown().optional().nullable(),
	newRowData: z.unknown().optional().nullable(),
	pubValueId: z.string().optional().nullable(),
	userId: usersIdSchema.optional().nullable(),
	apiAccessTokenId: apiAccessTokensIdSchema.optional().nullable(),
	actionRunId: actionRunsIdSchema.optional().nullable(),
	other: z.string().optional().nullable(),
})
