class RoutingFormResponseRepository {
  constructor(prismaClient) {
    this.prismaClient = prismaClient;
  }
  generateCreateFormResponseData(input) {
    return {
      formId: input.formId,
      response: input.response,
      chosenRouteId: input.chosenRouteId,
      ...input.queuedFormResponseId ? {
        queuedFormResponse: {
          connect: {
            id: input.queuedFormResponseId
          }
        }
      } : {}
    };
  }
  async recordFormResponse(input) {
    return await this.prismaClient.app_RoutingForms_FormResponse.create({
      data: this.generateCreateFormResponseData(input)
    });
  }
  async recordQueuedFormResponse(input) {
    return await this.prismaClient.app_RoutingForms_QueuedFormResponse.create({
      data: this.generateCreateFormResponseData(input)
    });
  }
  async findFormResponseIncludeForm({ routingFormResponseId }) {
    return await this.prismaClient.app_RoutingForms_FormResponse.findUnique({
      where: {
        id: routingFormResponseId
      },
      select: {
        response: true,
        form: {
          select: {
            routes: true,
            fields: true
          }
        },
        chosenRouteId: true
      }
    });
  }
  async findQueuedFormResponseIncludeForm({ queuedFormResponseId }) {
    return await this.prismaClient.app_RoutingForms_QueuedFormResponse.findUnique({
      where: {
        id: queuedFormResponseId
      },
      select: {
        response: true,
        form: {
          select: {
            routes: true,
            fields: true
          }
        },
        chosenRouteId: true
      }
    });
  }
  async getQueuedFormResponseFromId(id) {
    return await this.prismaClient.app_RoutingForms_QueuedFormResponse.findUnique({
      where: {
        id
      },
      select: {
        id: true,
        formId: true,
        response: true,
        chosenRouteId: true,
        createdAt: true,
        updatedAt: true,
        actualResponseId: true,
        form: {
          select: {
            team: {
              select: {
                parentId: true
              }
            },
            user: {
              select: {
                id: true,
                email: true
              }
            },
            id: true,
            description: true,
            position: true,
            routes: true,
            createdAt: true,
            updatedAt: true,
            name: true,
            fields: true,
            updatedById: true,
            userId: true,
            teamId: true,
            disabled: true,
            settings: true
          }
        }
      }
    });
  }
}
export {
  RoutingFormResponseRepository as R
};
