import { graphql } from './graphql'

import * as FragmentsClient from './fragments.client'

export const DeleteEmailDraft = graphql(
  `
    mutation DeleteEmailDraft(
      $teamId: ID!
      $instructor: Boolean!
      $emailThreadId: ID
    ) {
      deleteEmailDraft(
        teamId: $teamId
        instructor: $instructor
        emailThreadId: $emailThreadId
      ) @client {
        operationDone
      }
    }
  `,
  []
)

export const ReloadDefinitions = graphql(
  `
    mutation ReloadDefinitions {
      reloadDefinitions @client {
        operationDone
      }
    }
  `,
  []
)

export const ReloadExercises = graphql(
  `
    mutation ReloadExercises {
      reloadExercises @client {
        operationDone
      }
    }
  `,
  []
)

export const ReloadTable = graphql(
  `
    mutation ReloadTable {
      reloadTable @client {
        operationDone
      }
    }
  `,
  []
)

export const SetEmailDraft = graphql(
  `
    mutation SetEmailDraft($emailDraft: EmailDraftInput!) {
      setEmailDraft(emailDraft: $emailDraft) @client {
        ...EmailDraft
      }
    }
  `,
  [FragmentsClient.EmailDraft]
)

export const SetEmailThreadArchive = graphql(
  `
    mutation SetEmailThreadArchive($emailThreadId: ID!, $state: Boolean!) {
      setArchiveEmail(emailThreadId: $emailThreadId, state: $state) {
        id
        archived
      }
    }
  `,
  []
)

export const SetTeamSubscribe = graphql(
  `
    mutation SetTeamSubscribe($teamId: ID!, $state: Boolean!) {
      setSubscriptionTeam(teamId: $teamId, state: $state) {
        id
      }
    }
  `,
  []
)

export const setIsUnreadChannel = graphql(
  `
    mutation setIsUnreadChannel(
      $channelId: ID!
      $teamId: ID!
      $isUnread: Boolean!
    ) {
      setIsUnreadChannel(
        channelId: $channelId
        teamId: $teamId
        isUnread: $isUnread
      ) @client {
        id
        readReceipt {
          id
          isUnread
          teamId
        }
      }
    }
  `,
  []
)

export const setIsUnreadEmailThread = graphql(
  `
    mutation setIsUnreadEmailThread(
      $threadId: ID!
      $teamId: ID!
      $isUnread: Boolean!
    ) {
      setIsUnreadEmailThread(
        threadId: $threadId
        teamId: $teamId
        isUnread: $isUnread
      ) @client {
        id
        readReceipt {
          id
          isUnread
          teamId
        }
      }
    }
  `,
  []
)

export const SetTodoActionLog = graphql(
  `
    mutation SetTodoActionLog($actionLogId: ID!, $state: Boolean!) {
      setTodoActionLog(actionLogId: $actionLogId, state: $state) {
        id
        todo
      }
    }
  `,
  []
)

export const SetEmailTodo = graphql(
  `
    mutation SetEmailTodo($emailId: ID!, $state: Boolean!) {
      setEmailTodo(emailId: $emailId, state: $state) {
        id
        todo
      }
    }
  `,
  []
)

export const SetTeamQuestionnaireTodo = graphql(
  `
    mutation SetTeamQuestionnaireTodo(
      $teamQuestionnaireId: ID!
      $state: Boolean!
    ) {
      setTeamQuestionnaireTodo(
        teamQuestionnaireId: $teamQuestionnaireId
        state: $state
      ) {
        id
        todo
      }
    }
  `,
  []
)

export const WriteReadReceipt = graphql(
  `
    mutation WriteReadReceipt($actionLogId: ID!) {
      writeReadReceipt(actionLogId: $actionLogId) @client {
        id
        readReceipt
      }
    }
  `,
  []
)

export const WriteReadReceiptEmail = graphql(
  `
    mutation WriteReadReceiptEmail($emailId: ID!) {
      writeReadReceiptEmail(emailId: $emailId) @client {
        id
        readReceipt
      }
    }
  `,
  []
)
