# Mutations

## Authentication

### `register`

```graphql
mutation {
  register(email: "user@example.com", password: "securePass123!", recaptcha_token: "token") {
    success
    message
  }
}
```

### `login`

```graphql
mutation {
  login(email: "user@example.com", password: "pass", recaptcha_token: "token") {
    ... on AuthPayload {
      accessToken
      refreshToken
      idToken
    }
    ... on TwoFactorRequired {
      user_id
      message
    }
  }
}
```

### `verify_2fa_code`

```graphql
mutation {
  verify_2fa_code(user_id: "user_123", token: "123456") {
    accessToken
    refreshToken
  }
}
```

### `refresh_token`

```graphql
mutation {
  refresh_token(token: "refresh_token_here") {
    accessToken
    refreshToken
  }
}
```

### `logout` / `logout_all`

```graphql
mutation { logout(token: "refresh_token") }
mutation { logout_all }
```

### OAuth

```graphql
mutation { google_auth(token: "google_oauth_token") { ... on AuthPayload { accessToken } } }
mutation { x_auth(token: "twitter_oauth_token") { ... on AuthPayload { accessToken } } }
mutation { apple_auth(token: "apple_id_token") { ... on AuthPayload { accessToken } } }
```

### Email Verification

```graphql
mutation { verify_email(token: "verification_token") { accessToken } }
```

### Password Recovery

```graphql
mutation { forgot_password(email: "user@example.com", recaptcha_token: "token") { success message } }
mutation { reset_password(token: "reset_token", password: "newPass123!") { success message } }
```

### 2FA Management

```graphql
mutation { generate_2fa { secret qr_code } }
mutation { enable_2fa(token: "123456") }
mutation { disable_2fa }
```

## User

### `change_email`

```graphql
mutation { change_email(new_email: "new@example.com") { success message } }
```

### `confirm_email_change`

```graphql
mutation { confirm_email_change(token: "token") { success message } }
```

### `change_password`

```graphql
mutation { change_password(current_password: "old", new_password: "new") { success message } }
```

## Organizations

```graphql
mutation { createOrganization(input: { name: "My Org", description: "..." }) { id name } }
mutation { updateOrganization(id: "org_123", input: { name: "Updated" }) { id name } }
mutation { deleteOrganization(id: "org_123") }
mutation { inviteUserToOrganization(organization_id: "org_123", email: "user@example.com", role: "member") }
mutation { removeUserFromOrganization(organization_id: "org_123", user_id: "user_456") }
```

## Exchange Accounts

```graphql
mutation {
  createExchangeAccount(input: {
    exchange_name: "binance"
    account_name: "My Binance"
    trading_type: "spot"
    api_key: "..."
    api_secret: "..."
  }) { id exchange_name is_active }
}
```

```graphql
mutation { deleteExchangeAccount(id: "exc_123") }
mutation { syncExchangeBalance(id: "exc_123") { id balance last_sync_at } }
mutation { test_exchange_account(account: { exchange_name: "binance", api_key: "...", api_secret: "..." }) { success error } }
```

## Strategies

```graphql
mutation {
  create_strategy(strategy: {
    exchange_account_id: "exc_123"
    name: "BTC Momentum"
    risk_level: 3
  }) { success data { id name } }
}
```

```graphql
mutation { update_strategy(strategy: { id: "str_123", name: "Updated" }) { success data { id } } }
mutation { delete_strategy(id: "str_123") { success } }
mutation { link_copiers(strategy_id: "str_123", copier_ids: ["cop_456"]) { success linked_count } }
```

## Copiers

```graphql
mutation {
  create_copier(copier: {
    exchange_account_id: "exc_456"
    strategy_id: "str_123"
    name: "My Copier"
  }) { success data { id name } }
}
```

```graphql
mutation { update_copier(copier: { id: "cop_123", name: "Updated" }) { success } }
mutation { delete_copier(id: "cop_123") { success } }
mutation { toggleCopierStatus(id: "cop_123") { id is_active } }
```

## Trades

```graphql
mutation {
  createTrade(input: {
    exchange_account_id: "exc_123"
    trade_pair_id: "tp_btcusdt"
    type: "LIMIT"
    side: "BUY"
    price: 50000
    amount: 0.1
  }) { id status }
}
```

```graphql
mutation { cancelTrade(id: "trd_123") { id status } }
```

## Notifications

```graphql
mutation { markNotificationAsRead(id: "notif_123") { id } }
mutation { markAllNotificationsAsRead }
mutation { deleteNotification(id: "notif_123") }
```

## Settings

```graphql
mutation { updateUserSetting(key: "theme", value: "dark") { key value } }
mutation { deleteUserSetting(key: "theme") }
```

## Rewards & Withdrawals

```graphql
mutation { claimReward(reward_id: "rwd_123") { id } }
mutation { createWithdraw(input: { amount: 100, wallet_address: "0x..." }) { id } }
mutation { cancelWithdraw(id: "wd_123") { id } }
```

## Onboarding

```graphql
mutation { completeOnboarding { success } }
mutation { resetOnboarding { success } }
mutation { trackOnboardingEvent(event: "exchange_connected", stepId: "step1") }
```

## Passkeys

```graphql
mutation { generatePasskeyRegistrationChallenge { success data { challenge rp { id name } } } }
mutation { registerPasskey(credential: "...", device_name: "MacBook") { success data { id device_name } } }
mutation { generatePasskeyLoginChallenge(email: "user@example.com") { success data { challenge rpId } } }
mutation { loginWithPasskey(credential: "...", recaptcha_token: "token") { accessToken refreshToken } }
mutation { deletePasskey(id: "pk_123") { success } }
mutation { renamePasskey(id: "pk_123", device_name: "Work Laptop") { success } }
```

## Admin Mutations

```graphql
mutation { updateUserStatus(user_id: "user_123", is_active: false) { id is_active } }
mutation { grantSystemAdmin(user_id: "user_123") { id is_system_admin } }
mutation { revokeSystemAdmin(user_id: "user_123") { id is_system_admin } }
mutation { adminResetUserPassword(user_id: "user_123") { success temporary_password } }
mutation { adminChangeUserEmail(user_id: "user_123", new_email: "new@example.com") { success } }
mutation { adminResetUser2FA(user_id: "user_123") { success } }
mutation { adminDeactivateUser(user_id: "user_123", reason: "TOS violation") { success } }
mutation { adminReactivateUser(user_id: "user_123") { success } }
mutation { adminToggleSystemAdmin(user_id: "user_123", is_admin: true) { success } }
mutation { adminEnableApiKey(key_id: "key_123", type: "rest") { success } }
```
