(1) An in-state prisoner may petition for writ of habeas corpus to challenge the legality of a detainer which has been lodged against him by another state under the interstate agreement on detainers, chapter 50, title 19, Idaho Code.
(2)  The court may set a hearing on a petition for writ of habeas corpus to inquire into factual issues involving the legality of the detainer or the legality of delivery of the prisoner to the prosecuting state under the detainer. However, if the petition involves legal issues only, the court shall decide the matter without hearing consistent with section 19-4209, Idaho Code.