import type { ColumnType, Insertable, Selectable, Updateable } from "kysely"
import type { ApiAccessPermissionConstraints } from "../types"
import type { ApiAccessScope } from "./ApiAccessScope"
import type { ApiAccessTokensId } from "./ApiAccessTokens"
import type { ApiAccessType } from "./ApiAccessType"

import { z } from "zod"

import { apiAccessScopeSchema } from "./ApiAccessScope"
import { apiAccessTokensIdSchema } from "./ApiAccessTokens"
import { apiAccessTypeSchema } from "./ApiAccessType"

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

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

/** Represents the table public.api_access_permissions */
export interface ApiAccessPermissionsTable {
	id: ColumnType<
		ApiAccessPermissionsId,
		ApiAccessPermissionsId | undefined,
		ApiAccessPermissionsId
	>

	apiAccessTokenId: ColumnType<ApiAccessTokensId, ApiAccessTokensId, ApiAccessTokensId>

	scope: ColumnType<ApiAccessScope, ApiAccessScope, ApiAccessScope>

	accessType: ColumnType<ApiAccessType, ApiAccessType, ApiAccessType>

	constraints: ColumnType<
		ApiAccessPermissionConstraints | null,
		ApiAccessPermissionConstraints | null,
		ApiAccessPermissionConstraints | null
	>

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

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

export type ApiAccessPermissions = Selectable<ApiAccessPermissionsTable>

export type NewApiAccessPermissions = Insertable<ApiAccessPermissionsTable>

export type ApiAccessPermissionsUpdate = Updateable<ApiAccessPermissionsTable>

export const apiAccessPermissionsIdSchema = z
	.string()
	.uuid() as unknown as z.Schema<ApiAccessPermissionsId>

export const apiAccessPermissionsSchema = z.object({
	id: apiAccessPermissionsIdSchema,
	apiAccessTokenId: apiAccessTokensIdSchema,
	scope: apiAccessScopeSchema,
	accessType: apiAccessTypeSchema,
	constraints: z.unknown().nullable(),
	createdAt: z.date(),
	updatedAt: z.date(),
})

export const apiAccessPermissionsInitializerSchema = z.object({
	id: apiAccessPermissionsIdSchema.optional(),
	apiAccessTokenId: apiAccessTokensIdSchema,
	scope: apiAccessScopeSchema,
	accessType: apiAccessTypeSchema,
	constraints: z.unknown().optional().nullable(),
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
})

export const apiAccessPermissionsMutatorSchema = z.object({
	id: apiAccessPermissionsIdSchema.optional(),
	apiAccessTokenId: apiAccessTokensIdSchema.optional(),
	scope: apiAccessScopeSchema.optional(),
	accessType: apiAccessTypeSchema.optional(),
	constraints: z.unknown().optional().nullable(),
	createdAt: z.date().optional(),
	updatedAt: z.date().optional(),
})
