In your situation the security guard can threaten you with detainment at your apartment complex because he did. Whether you are required to comply with the request by the security officer is another question. He most likely was not law enforcement (police officer or sheriff). As such, you were not under any legal obligation to agree to to his request.However, the security officer does have a job to do by making sure that the complex where you live is safe. He observed you sitting in your vehicle in the early hours of the morning. This caused some suspicion on his part. He was then justified in asking you questions to make sure who you were, if you had identification and to make sure you were allowed to be where you were.Good question.