text: /**
   * Generated by `createschema notification.Message 'organization?:Relationship:Organization:CASCADE; property?:Relationship:Property:CASCADE; ticket?:Relationship:Ticket:CASCADE; user:Relationship:User:CASCADE; type:Text; meta:Json; channels:Json; status:Select:sending,planned,sent,canceled; deliveredAt:DateTimeUtc;'`
   * In most cases you should not change it by hands
   * Please, don't remove `AUTOGENERATE MARKER`s
   */
  
  const { LOCALES } = require('@condo/domains/common/constants/locale')
  const { generateServerUtils, execGqlWithoutAccess } = require('@condo/domains/common/utils/codegeneration/generate.server.utils')
  
  const {
      Message: MessageGQL,
      SEND_MESSAGE,
      RESEND_MESSAGE,
      Device: DeviceGQL,
      SYNC_DEVICE_MUTATION,
  } = require('@condo/domains/notification/gql')
  
  const { MESSAGE_TYPES } = require('@condo/domains/notification/constants/constants')
  
  const { DISCONNECT_USER_FROM_DEVICE_MUTATION } = require('@condo/domains/notification/gql')
  const { SET_MESSAGE_STATUS_MUTATION } = require('@condo/domains/notification/gql')
  /* AUTOGENERATE MARKER <IMPORT> */
  
  const Message = generateServerUtils(MessageGQL)
  
  async function sendMessage (context, data) {
      if (!context) throw new Error('no context')
      if (!data) throw new Error('no data')
      if (!data.sender) throw new Error('no data.sender')
      if (!data.to) throw new Error('no data.to')
      if (!data.to.email && !data.to.phone && !data.to.user) throw new Error('wrong data.to')
      if (!data.type) throw new Error('no data.type')
      if (!MESSAGE_TYPES.includes(data.type)) throw new Error('unknown data.type')
      if (!LOCALES[data.lang]) throw new Error('unknown data.lang')
  
      return await execGqlWithoutAccess(context, {
          query: SEND_MESSAGE,
          variables: { data: { dv: 1, ...data } },
          errorMessage: '[error] Unable to sendMessage',
          dataPath: 'result',
      })
  }
  
  async function resendMessage (context, data) {
      if (!context) throw new Error('no context')
      if (!data) throw new Error('no data')
      if (!data.message || !data.message.id) throw new Error('no data.message')
  
      return await execGqlWithoutAccess(context, {
          query: RESEND_MESSAGE,
          variables: { data },
          errorMessage: '[error] Unable to resendMessage',
          dataPath: 'result',
      })
  }
  
  const Device = generateServerUtils(DeviceGQL)
  
  /**
   * Connects a device that could be sent push notifications with user and/or pushToken
   * Should be called for:
   * 1. Registration of a device: required fields deviceId, optional fields: pushToken + pushTransport, user, meta
   * 2. Connection of a device to current authorized user: required fields: deviceId
   * 3. Update pushToken value: required field: deviceId, pushToken + pushTransport (pushTransport should always follow pushToken, in order to select proper push transport)
   * 4. Update meta value: required field: deviceId, meta
   * @param context
   * @param data
   * @returns {Promise<*>}
   */
  async function syncDevice (context, data) {
      if (!context) throw new Error('no context')
      if (!data) throw new Error('no data')
      if (!data.sender) throw new Error('no data.sender')
      if (!data.deviceId) throw new Error('no data.deviceId')
  
      return await execGqlWithoutAccess(context, {
          query: SYNC_DEVICE_MUTATION,
          variables: { data: { dv: 1, ...data } },
          errorMessage: '[error] Unable to syncDevice',
          dataPath: 'obj',
      })
  }
  
  async function disconnectUserFromDevice (context, data) {
      if (!context) throw new Error('no context')
      if (!data) throw new Error('no data')
      if (!data.sender) throw new Error('no data.sender')
      if (!data.deviceId) throw new Error('no data.deviceId')
  
      return await execGqlWithoutAccess(context, {
          query: DISCONNECT_USER_FROM_DEVICE_MUTATION,
          variables: { data: { dv: 1, ...data } },
          errorMessage: '[error] Unable to disconnectUserFromDevice',
          dataPath: 'obj',
      })
  }
  
  async function setMessageStatus (context, data) {
      if (!context) throw new Error('no context')
      if (!data) throw new Error('no data')
      if (!data.message || !data.message.id) throw new Error('no data.message')
      if (!data.deliveredAt && !data.readAt) throw new Error('no data.deliveredAt and data.readAt')
  
      return await execGqlWithoutAccess(context, {
          query: SET_MESSAGE_STATUS_MUTATION,
          variables: { data },
          errorMessage: '[error] Unable to setMessageStatus',
          dataPath: 'obj',
      })
  }
  
  /* AUTOGENERATE MARKER <CONST> */
  
  module.exports = {
      Message,
      sendMessage,
      resendMessage,
      Device,
      syncDevice,
      disconnectUserFromDevice,
      setMessageStatus,
  /* AUTOGENERATE MARKER <EXPORTS> */
  }
  