import { prismaClient } from '../database/prismaClient.js';
export async function createAgent(data) {
    console.log(`Creating Agent with ID: ${data.id}`);
    return prismaClient.agent.create({
        data,
    });
}
export async function getAgent(id) {
    console.log(`Getting Agent with ID: ${id}`);
    return prismaClient.agent.findUnique({
        where: { id },
    });
}
export async function listAgents() {
    console.log('Listing all Agents');
    return prismaClient.agent.findMany();
}
export async function listAgentsFiltered(filters) {
    console.log(`Listing Agents with filters: ${JSON.stringify(filters)}`);
    const chainIdsInBigInt = filters?.chainIds?.length
        ? filters.chainIds.map((chainId) => BigInt(chainId))
        : null;
    // Build `where` using Object.assign to keep it concise
    const where = {};
    Object.assign(where, {
        ...(chainIdsInBigInt && { chainIds: { hasEvery: chainIdsInBigInt } }),
        ...(filters?.verified !== undefined && { verified: filters.verified }),
        ...(filters?.categories?.length && {
            categories: { hasEvery: filters.categories },
        }),
        ...(filters?.accountId !== undefined && { accountId: filters.accountId }),
    });
    return prismaClient.agent.findMany({
        where,
        skip: filters?.offset,
        take: filters?.limit,
    });
}
export async function updateAgent(id, data) {
    console.log(`Updating Agent with ID: ${id}`);
    return prismaClient.agent.update({
        where: { id },
        data,
    });
}
export async function deleteAgent(id) {
    console.log(`Deleting Agent with ID: ${id}`);
    return prismaClient.agent.delete({
        where: { id },
    });
}
