/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import gql from 'graphql-tag';

export const fields = `
  rowId
  type
  code
  email
  username
  isActive
  clientId
  client {
    id
    rowId
    grantType
    name
    secret
    authUrl
    redirect
    scopeOptions
    accessTokenLifetimeSeconds
    refreshTokenLifetimeSeconds
    isActive
    isMaster
  }
  tags
  scopes
  dApplicationCodes
  dPermissions
  dTenants
  meta
  roles {
    id
    rowId
    name
    defaultRedirection
    hasHiddenVerticalNavigation
    isMaster
  }
  tenants {
    id
    rowId
    name
    code
    logo
    isActive
    meta
  }
  user {
    id
    rowId
    name
    surname
    avatar
    mobile
    langId
    isTwoFactorAuthenticationEnabled
    meta
  }
  createdAt
  updatedAt
`;

export const relationsFields = `
  iamGetTenants (
    query: $queryTenants
    constraint: $constraintTenants
  ) {
    id
    rowId
    name
    code
    logo
    isActive
    meta
  }
`;

// default methods
export const paginationQuery = gql`
  query IamPaginateAccounts($query: QueryStatement, $constraint: QueryStatement) {
    pagination: iamPaginateAccounts(query: $query, constraint: $constraint) {
      total
      rows
      count
    }
  }
`;

export const getQuery = gql`
  query IamGetAccounts($query: QueryStatement, $constraint: QueryStatement) {
    objects: iamGetAccounts(query: $query, constraint: $constraint) {
      id
      #FIELDS
    }
  }
`;

export const getRelations = gql`
  query IamGetAccountsRelations (
    $queryTenants: QueryStatement
    $constraintTenants: QueryStatement
  ) {
    ${relationsFields}
  }
`;

export const findByIdQuery = gql`
  query IamFindAccountById($id: ID, $constraint: QueryStatement) {
    object: iamFindAccountById(id: $id, constraint: $constraint) {
      id
      #FIELDS
    }
  }
`;

export const findByIdWithRelationsQuery = gql`
  query IamFindAccountByIdWithRelations (
    $id: ID
    $constraint: QueryStatement
    $queryTenants: QueryStatement
    $constraintTenants: QueryStatement
  ) {
    object: iamFindAccountById (
      id: $id
      constraint: $constraint
    ) {
      id
      #FIELDS
      tenants {
        id
        rowId
        name
        code
        logo
        isActive
        meta
      }
    }
    ${relationsFields}
  }
`;

export const findQuery = gql`
  query IamFindAccount($query: QueryStatement, $constraint: QueryStatement) {
    object: iamFindAccount(query: $query, constraint: $constraint) {
      id
      #FIELDS
    }
  }
`;

export const createMutation = gql`
  mutation IamCreateAccount (
    $payload: IamCreateAccountInput!
  ) {
    iamCreateAccount (
      payload: $payload
    ) {
      ${fields}
    }
  }
`;

export const insertMutation = gql`
  mutation IamCreateAccounts($payload: [IamCreateAccountInput]!) {
    iamCreateAccounts(payload: $payload)
  }
`;

export const updateByIdMutation = gql`
  mutation IamUpdateAccountById (
    $payload: IamUpdateAccountByIdInput!
    $constraint: QueryStatement
  ) {
    iamUpdateAccountById (
      payload: $payload
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

export const updateMutation = gql`
  mutation IamUpdateAccounts (
    $payload: IamUpdateAccountsInput!
    $query: QueryStatement
    $constraint: QueryStatement
  ) {
    iamUpdateAccounts (
      payload: $payload
      query: $query
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

export const deleteByIdMutation = gql`
  mutation IamDeleteAccountById (
    $id: ID!
    $constraint: QueryStatement
  ) {
    iamDeleteAccountById (
      id: $id
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

export const deleteMutation = gql`
  mutation IamDeleteAccounts (
    $query: QueryStatement
    $constraint: QueryStatement
  ) {
    iamDeleteAccounts (
      query: $query
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

// Queries additionalApis
export const meAccountQuery = gql`
  query IamMeAccount {
    iamMeAccount {
      email
      username
      user {
        name
        surname
      }
    }
  }
`;

export const checkPasswordMeAccountQuery = gql`
  query IamCheckPasswordMeAccount (
    $query: QueryStatement
    $constraint: QueryStatement
  ) {
    iamCheckPasswordMeAccount (
      query: $query
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

export const checkUniqueUsernameAccountQuery = gql`
  query IamCheckUniqueUsernameAccount($username: String!, $avoidUsernames: [String!]) {
    iamCheckUniqueUsernameAccount(username: $username, avoidUsernames: $avoidUsernames)
  }
`;

export const checkUniqueEmailAccountQuery = gql`
  query IamCheckUniqueEmailAccount($email: String!, $avoidEmails: [String!]) {
    iamCheckUniqueEmailAccount(email: $email, avoidEmails: $avoidEmails)
  }
`;

export const paginateWithTenantConstraintAccountsQuery = gql`
  query IamPaginateWithTenantConstraintAccounts (
    $query: QueryStatement
    $constraint: QueryStatement
  ) {
    iamPaginateWithTenantConstraintAccounts (
      query: $query
      constraint: $constraint
    ) {
      ${fields}
    }
  }
`;

// Mutation additionalApis
export const updateMeAccountMutation = gql`
  mutation IamUpdateMeAccount($payload: IamUpdateAccountByIdInput!, $constraint: QueryStatement) {
    iamUpdateMeAccount(payload: $payload, constraint: $constraint)
  }
`;
