//Prisma 'where' clause for DTO filters
export function buildPrismaWhere<T extends Record<string, any>>(dto: T): Record <string, any> {
    const where: Record<string,any> = {};

    for (const [key,value] of Object.entries(dto)) {
        if (value === undefined || value === null) continue;

        if (key.endsWith('_contains')) {
            const field = key.slice(0, - '_contains'.length);
            where[field] = { constains: value }; 
        } else if (key === 'start_date' || key === 'end_date') {
            where.date = where.date || {};
            const op = key === 'start_date' ? 'gte' : 'lte';
            where.date[op] = new Date(value);
        } else {
            where[key] = value;
        }
    }

    return where;
}