mutation createTeamMember(
  $teamId: UUID!
  $role: TeamMemberRole!
  $title: String
  $department: String
  $teamHubId: UUID
  $isActive: Boolean
  $userId: String!
  $inviteStatus: TeamMemberInviteStatus
) @auth(level: USER) {
  teamMember_insert(
    data: {
      teamId: $teamId
      role: $role
      title: $title
      department: $department
      teamHubId: $teamHubId
      isActive: $isActive
      userId: $userId
      inviteStatus: $inviteStatus
    }
  ) 
}

mutation updateTeamMember(
  $id: UUID!
  $role: TeamMemberRole
  $title: String
  $department: String
  $teamHubId: UUID
  $isActive: Boolean
  $inviteStatus: TeamMemberInviteStatus
) @auth(level: USER) {
  teamMember_update(
    id: $id
    data: {
      role: $role
      title: $title
      department: $department
      teamHubId: $teamHubId
      isActive: $isActive
      inviteStatus: $inviteStatus
    }
  ) 
}

mutation updateTeamMemberInviteStatus(
  $id: UUID!
  $inviteStatus: TeamMemberInviteStatus!
) @auth(level: USER) {
  teamMember_update(
    id: $id
    data: {
      inviteStatus: $inviteStatus
    }
  )
}

mutation acceptInviteByCode(
  $inviteCode: UUID!
) @auth(level: USER) {
  teamMember_updateMany(
    where: {
      inviteCode: { eq: $inviteCode }
      inviteStatus: { eq: PENDING }
    }
    data: {
      inviteStatus: ACCEPTED
      isActive: true
    }
  )
}

mutation cancelInviteByCode(
  $inviteCode: UUID!
) @auth(level: USER) {
  teamMember_updateMany(
    where: {
      inviteCode: { eq: $inviteCode }
      inviteStatus: { eq: PENDING }
    }
    data: {
      inviteStatus: CANCELLED
      isActive: false
    }
  )
}


mutation deleteTeamMember($id: UUID!) @auth(level: USER) {
  teamMember_delete(id: $id) 
}
