import { QueryBuilder, buildFindManyDocument, buildFindFirstDocument, buildCreateDocument, buildUpdateByPkDocument, buildDeleteByPkDocument, } from '../query-builder';
import { connectionFieldsMap } from '../input-types';
export class TableModel {
    client;
    constructor(client) {
        this.client = client;
    }
    findMany(args) {
        const { document, variables } = buildFindManyDocument('Table', 'tables', args.select, {
            where: args?.where,
            orderBy: args?.orderBy,
            first: args?.first,
            last: args?.last,
            after: args?.after,
            before: args?.before,
            offset: args?.offset,
        }, 'TableFilter', 'TableOrderBy', connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'query',
            operationName: 'Table',
            fieldName: 'tables',
            document,
            variables,
        });
    }
    findFirst(args) {
        const { document, variables } = buildFindFirstDocument('Table', 'tables', args.select, {
            where: args?.where,
            orderBy: args?.orderBy,
        }, 'TableFilter', 'TableOrderBy', connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'query',
            operationName: 'Table',
            fieldName: 'table',
            document,
            variables,
            transform: (data) => ({
                table: data.tables?.nodes?.[0] ?? null,
            }),
        });
    }
    findOne(args) {
        const { document, variables } = buildFindManyDocument('Table', 'tables', args.select, {
            where: {
                id: {
                    equalTo: args.id,
                },
            },
            first: 1,
        }, 'TableFilter', 'TableOrderBy', connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'query',
            operationName: 'Table',
            fieldName: 'table',
            document,
            variables,
            transform: (data) => ({
                table: data.tables?.nodes?.[0] ?? null,
            }),
        });
    }
    create(args) {
        const { document, variables } = buildCreateDocument('Table', 'createTable', 'table', args.select, args.data, 'CreateTableInput', connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'mutation',
            operationName: 'Table',
            fieldName: 'createTable',
            document,
            variables,
        });
    }
    update(args) {
        const { document, variables } = buildUpdateByPkDocument('Table', 'updateTable', 'table', args.select, args.where.id, args.data, 'UpdateTableInput', 'id', 'tablePatch', connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'mutation',
            operationName: 'Table',
            fieldName: 'updateTable',
            document,
            variables,
        });
    }
    delete(args) {
        const { document, variables } = buildDeleteByPkDocument('Table', 'deleteTable', 'table', {
            id: args.where.id,
        }, 'DeleteTableInput', args.select, connectionFieldsMap);
        return new QueryBuilder({
            client: this.client,
            operation: 'mutation',
            operationName: 'Table',
            fieldName: 'deleteTable',
            document,
            variables,
        });
    }
}
