import { gql } from '@apollo/client'

export const GET_USERS_QUERY = gql`
  query GetUsers(
    $page: Int!
    $query: String
    $orgs: [ID!]
    $roles: [Role!]
    $sortDirection: SortDirection!
    $sortField: UserSortField!
  ) {
    getUsers(
      page: $page
      query: $query
      orgs: $orgs
      roles: $roles
      sortDirection: $sortDirection
      sortField: $sortField
    ) {
      totalPages
      totalElements
      page {
        avatarUrl
        firstName
        id
        lastName
        middleName
        org {
          creationDate
          id
          logoUrl
          name
        }
        orgId
        role
        username
      }
    }
  }
`

export const GET_ORGANISATION_QUERY = gql`
  query GetOrganisation($id: ID!) {
    getOrganisation(id: $id) {
      creationDate
      id
      name
      logoUrl
      policy {
        bluetooth
        bluetoothEditable
        camera
        cameraEditable
        GPS
        gpsEditable
        sim
        simEditable
        offlineTimeThreshold
      }
    }
  }
`

export const DELETE_ORGANISATION_MUTATION = gql`
  mutation DeleteOrganisation($id: ID!) {
    deleteOrganisation(id: $id)
  }
`

export const GET_ORGANISATIONS_QUERY = gql`
  query GetOrganisations(
    $page: Int!
    $query: String
    $sortDirection: SortDirection!
    $sortField: OrganisationSortField!
  ) {
    getOrganisations(
      page: $page
      query: $query
      sortDirection: $sortDirection
      sortField: $sortField
    ) {
      totalPages
      totalElements
      page {
        creationDate
        id
        name
        logoUrl
      }
    }
  }
`

export const CREATE_ORGANISATION_MUTATION = gql`
  mutation CreateOrganisation(
    $name: String!
    $bluetooth: ServiceUseOption!
    $bluetoothEditable: Boolean!
    $camera: ComponentUseOption!
    $cameraEditable: Boolean!
    $GPS: ServiceUseOption!
    $gpsEditable: Boolean!
    $sim: ServiceUseOption!
    $simEditable: Boolean!
    $offlineTimeThreshold: Float!
  ) {
    createOrganisation(
      name: $name
      policy: {
        bluetooth: $bluetooth
        bluetoothEditable: $bluetoothEditable
        camera: $camera
        cameraEditable: $cameraEditable
        GPS: $GPS
        gpsEditable: $gpsEditable
        sim: $sim
        simEditable: $simEditable
        offlineTimeThreshold: $offlineTimeThreshold
      }
    ) {
      id
      name
    }
  }
`

export const CHANGE_ORGANISATION_MUTATION = gql`
  mutation ChangeOrganisation(
    $id: ID!
    $name: String!
    $bluetooth: ServiceUseOption!
    $bluetoothEditable: Boolean!
    $camera: ComponentUseOption!
    $cameraEditable: Boolean!
    $GPS: ServiceUseOption!
    $gpsEditable: Boolean!
    $sim: ServiceUseOption!
    $simEditable: Boolean!
    $offlineTimeThreshold: Float!
  ) {
    changeOrganisation(
      id: $id
      name: $name
      policy: {
        bluetooth: $bluetooth
        bluetoothEditable: $bluetoothEditable
        camera: $camera
        cameraEditable: $cameraEditable
        GPS: $GPS
        gpsEditable: $gpsEditable
        sim: $sim
        simEditable: $simEditable
        offlineTimeThreshold: $offlineTimeThreshold
      }
    ) {
      creationDate
      id
      name
    }
  }
`

export const CHANGE_ORGANISATION_POLICY_MUTATION = gql`
  mutation ChangeOrganisationPolicy(
    $id: ID!
    $name: String!
    $bluetooth: ServiceUseOption!
    $bluetoothEditable: Boolean!
    $camera: ComponentUseOption!
    $cameraEditable: Boolean!
    $GPS: ServiceUseOption!
    $gpsEditable: Boolean!
    $sim: ServiceUseOption!
    $simEditable: Boolean!
    $offlineTimeThreshold: Float!
  ) {
    changeOrganisation(
      id: $id
      name: $name
      policy: {
        bluetooth: $bluetooth
        bluetoothEditable: $bluetoothEditable
        camera: $camera
        cameraEditable: $cameraEditable
        GPS: $GPS
        gpsEditable: $gpsEditable
        sim: $sim
        simEditable: $simEditable
        offlineTimeThreshold: $offlineTimeThreshold
      }
    ) {
      creationDate
      id
      name
    }
  }
`

export const CREATE_USER_MUTATION = gql`
  mutation createUser(
    $orgId: ID!
    $firstName: String!
    $lastName: String!
    $middleName: String!
    $username: String!
    $password: String!
    $role: Role!
  ) {
    createUser(
      payload: {
        orgId: $orgId
        firstName: $firstName
        lastName: $lastName
        middleName: $middleName
        username: $username
        password: $password
        role: $role
      }
    ) {
      id
      firstName
      lastName
      middleName
      orgId
      role
      org {
        id
        name
      }
    }
  }
`

export const CHANGE_USER_MUTATION = gql`
  mutation ChangeUser(
    $userId: ID!
    $orgId: ID!
    $firstName: String!
    $lastName: String!
    $middleName: String!
    $username: String!
    $role: Role!
  ) {
    changeUser(
      userId: $userId
      form: {
        orgId: $orgId
        firstName: $firstName
        lastName: $lastName
        middleName: $middleName
        username: $username
        role: $role
      }
    ) {
      avatarUrl
      firstName
      id
      lastName
      middleName
      org {
        creationDate
        id
        logoUrl
        name
      }
      orgId
      role
      username
    }
  }
`

export const CHANGE_USER_WITH_PASSWORD_MUTATION = gql`
  mutation ChangeUserWithPassword(
    $userId: ID!
    $orgId: ID!
    $firstName: String!
    $lastName: String!
    $middleName: String!
    $username: String!
    $password: String!
    $role: Role!
  ) {
    changeUser(
      userId: $userId
      form: {
        orgId: $orgId
        firstName: $firstName
        lastName: $lastName
        middleName: $middleName
        username: $username
        password: $password
        role: $role
      }
    ) {
      avatarUrl
      firstName
      id
      lastName
      middleName
      org {
        creationDate
        id
        logoUrl
        name
      }
      orgId
      role
      username
    }
  }
`

export const CREATE_UPLOAD_USER_AVATAR_URL_MUTATION = gql`
  mutation CreateUploadUserAvatarUrl($userId: ID!) {
    createUploadUserAvatarUrl(userId: $userId)
  }
`

export const CREATE_UPLOAD_ORGANISATION_LOGO_URL_MUTATION = gql`
  mutation CreateUploadOrganisationLogoUrl($orgId: ID!) {
    createUploadOrganisationLogoUrl(orgId: $orgId)
  }
`
