import { graphql } from '../generated'

export const USER_FIELDS = graphql(`
  fragment UserFields on User {
    id
    lastName
    firstName
    middleName
    email
    login
    role
    active
    createdAt
    updatedAt
  }
`)

export const GET_USERS_QUERY = graphql(`
  query GetUsers(
    $page: Int!
    $pageSize: Int
    $query: String
    $roles: [UserRole!]
    $sortDirection: SortDirection!
    $sortField: UserSortField!
  ) {
    getUsers(
      page: $page
      pageSize: $pageSize
      query: $query
      roles: $roles
      sortDirection: $sortDirection
      sortField: $sortField
    ) {
      totalPages
      totalElements
      page {
        ...UserFields
      }
    }
  }
`)

export const GET_USER_QUERY = graphql(`
  query GetUser($id: Long!) {
    getUser(id: $id) {
      ...UserFields
    }
  }
`)

export const CREATE_USER_MUTATION = graphql(`
  mutation CreateUser($payload: CreateUserPayload!) {
    createUser(payload: $payload) {
      ...UserFields
    }
  }
`)

export const UPDATE_USER_MUTATION = graphql(`
  mutation UpdateUser($id: Long!, $payload: UpdateUserPayload!) {
    updateUser(id: $id, payload: $payload) {
      ...UserFields
    }
  }
`)

export const DELETE_USER_MUTATION = graphql(`
  mutation DeleteUser($id: Long!) {
    deleteUser(id: $id)
  }
`)
