import prisma from '@/lib/prisma'; import { Prisma, Segment } from '@prisma/client'; async function findSegment(criteria: Prisma.SegmentFindUniqueArgs): Promise { return prisma.client.Segment.findUnique(criteria); } export async function getSegment(segmentId: string): Promise { return findSegment({ where: { id: segmentId, }, }); } export async function getWebsiteSegment( websiteId: string, type: string, name: string, ): Promise { return prisma.client.segment.findFirst({ where: { websiteId, type, name }, }); } export async function getWebsiteSegments(websiteId: string, type: string): Promise { return prisma.client.Segment.findMany({ where: { websiteId, type }, }); } export async function createSegment(data: Prisma.SegmentUncheckedCreateInput): Promise { return prisma.client.Segment.create({ data }); } export async function updateSegment( SegmentId: string, data: Prisma.SegmentUpdateInput, ): Promise { return prisma.client.Segment.update({ where: { id: SegmentId }, data }); } export async function deleteSegment(SegmentId: string): Promise { return prisma.client.Segment.delete({ where: { id: SegmentId } }); }