import type { ColumnType, Insertable, Selectable, Updateable } from "kysely"
import type { BaseActionInstanceConfig } from "../types"
import type { Action } from "./Action"
import type { StagesId } from "./Stages"

import { z } from "zod"

import { actionSchema } from "./Action"
import { stagesIdSchema } from "./Stages"

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

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

/** Represents the table public.action_instances */
export interface ActionInstancesTable {
	id: ColumnType<ActionInstancesId, ActionInstancesId | undefined, ActionInstancesId>

	stageId: ColumnType<StagesId, StagesId, StagesId>

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

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

	config: ColumnType<
		BaseActionInstanceConfig | null,
		BaseActionInstanceConfig | null,
		BaseActionInstanceConfig | null
	>

	name: ColumnType<string, string | undefined, string>

	action: ColumnType<Action, Action, Action>
}

export type ActionInstances = Selectable<ActionInstancesTable>

export type NewActionInstances = Insertable<ActionInstancesTable>

export type ActionInstancesUpdate = Updateable<ActionInstancesTable>

export const actionInstancesIdSchema = z.string().uuid() as unknown as z.Schema<ActionInstancesId>

export const actionInstancesSchema = z.object({
	id: actionInstancesIdSchema,
	stageId: stagesIdSchema,
	createdAt: z.date(),
	updatedAt: z.date(),
	config: z.unknown().nullable(),
	name: z.string(),
	action: actionSchema,
})

export const actionInstancesInitializerSchema = z.object({
	id: actionInstancesIdSchema.optional(),
	stageId: stagesIdSchema,
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
	config: z.unknown().optional().nullable(),
	name: z.string().optional(),
	action: actionSchema,
})

export const actionInstancesMutatorSchema = z.object({
	id: actionInstancesIdSchema.optional(),
	stageId: stagesIdSchema.optional(),
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
	config: z.unknown().optional().nullable(),
	name: z.string().optional(),
	action: actionSchema.optional(),
})
