import java.util.Scanner;
import javax.ejb.*;
import javax.persistence.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;

@Path("/question")
@Stateless
public class QuestionService {
   @PersistenceContext(unitName="default")
   private EntityManager em;

   @GET
   @Path("/init")
   @Produces("text/plain")
   public Response init() {
       String[] inputs = {
           "What trademarked slogan describes Java development? Write once, ...\n*run anywhere\ndebug everywhere\nrun many times\nread anywhere\n",
           "What are the first 4 bytes of every class file (in hexadecimal)?\nJAVA\n0xFFFE or 0xFEFF\n*0xCAFEBABE\nPK\n",
           "Which Java keyword is used to define a subclass?\nsub\nsuper\n*extends\nimplements\n",
           "What was the original name of the Java programming language?\n!C++\n*Oak\nJ++\nStar 7\n",
           "Which Java class describes a point in time?\njava.util.Time\njava.sql.Time\njava.lang.TimeOfDay\njava.util.Date"
       };

       String ids = "";
       for (int i = 0; i < inputs.length; i++) {
           Question q = new Question();
           q.read(new Scanner(inputs[i]));
           for (Choice c : q.getChoices()) em.persist(c);
           em.persist(q);
           if (i > 0) ids += ", ";
           ids += q.getId();
       }

      return Response.status(200).entity("" + ids).build();
   }

    @GET
    @Path("/{id}")
    public Response getQuestion(@PathParam("id") int id) {
        return null;
    }
}
