import type { ColumnType, Insertable, Selectable, Updateable } from "kysely"
import type { LastModifiedBy } from "../types"
import type { PubFieldsId } from "./PubFields"
import type { PubsId } from "./Pubs"

import { z } from "zod"

import { modifiedByTypeSchema } from "./ModifiedByType"
import { pubFieldsIdSchema } from "./PubFields"
import { pubsIdSchema } from "./Pubs"

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

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

/** Represents the table public.pub_values */
export interface PubValuesTable {
	id: ColumnType<PubValuesId, PubValuesId | undefined, PubValuesId>

	fieldId: ColumnType<PubFieldsId, PubFieldsId, PubFieldsId>

	value: ColumnType<unknown | null, unknown | null, unknown | null>

	pubId: ColumnType<PubsId, PubsId, PubsId>

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

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

	relatedPubId: ColumnType<PubsId | null, PubsId | null, PubsId | null>

	lastModifiedBy: ColumnType<LastModifiedBy, LastModifiedBy, LastModifiedBy>

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

export type PubValues = Selectable<PubValuesTable>

export type NewPubValues = Insertable<PubValuesTable>

export type PubValuesUpdate = Updateable<PubValuesTable>

export const pubValuesIdSchema = z.string().uuid() as unknown as z.Schema<PubValuesId>

export const pubValuesSchema = z.object({
	id: pubValuesIdSchema,
	fieldId: pubFieldsIdSchema,
	value: z.unknown().nullable(),
	pubId: pubsIdSchema,
	createdAt: z.date(),
	updatedAt: z.date(),
	relatedPubId: pubsIdSchema.nullable(),
	lastModifiedBy: modifiedByTypeSchema,
	rank: z.string().nullable(),
})

export const pubValuesInitializerSchema = z.object({
	id: pubValuesIdSchema.optional(),
	fieldId: pubFieldsIdSchema,
	value: z.unknown().optional().nullable(),
	pubId: pubsIdSchema,
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
	relatedPubId: pubsIdSchema.optional().nullable(),
	lastModifiedBy: modifiedByTypeSchema,
	rank: z.string().optional().nullable(),
})

export const pubValuesMutatorSchema = z.object({
	id: pubValuesIdSchema.optional(),
	fieldId: pubFieldsIdSchema.optional(),
	value: z.unknown().optional().nullable(),
	pubId: pubsIdSchema.optional(),
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
	relatedPubId: pubsIdSchema.optional().nullable(),
	lastModifiedBy: modifiedByTypeSchema.optional(),
	rank: z.string().optional().nullable(),
})
