/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.service;

import com.demo.Person;
import com.demo.PhoneNumber;
import java.util.ArrayList;
import java.util.List;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.json.bind.JsonbConfig;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;

/**
 * REST Web Service
 *
 * @author Administrator
 */
@Path("jsondemo")
public class GenericResource {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of GenericResource
     */
    public GenericResource() {
    }

    /**
     * Retrieves representation of an instance of com.service.GenericResource
     *
     * @return an instance of java.lang.String
     */
    @GET

    @Produces({"application/json"})

    public String getJson() {
        //TODO return proper representation object
        List<Person> jasons = new ArrayList<>(3);

        List<PhoneNumber> Phones1 = new ArrayList<>(2);
        Phones1.add(new PhoneNumber("home", "123 456 789"));
        Phones1.add(new PhoneNumber("work", "123 555 555"));

        jasons.add(new Person("Peter", "CEO", Phones1));

        List<PhoneNumber> Phones2 = new ArrayList<>(1);
        Phones2.add(new PhoneNumber("home", "666 666 666"));

        jasons.add(new Person("John", "CFO", Phones2));
        jasons.add(new Person("Mike", "CIO", null));

        JsonbConfig config = new JsonbConfig()
                .withFormatting(true);
        Jsonb jsonb = JsonbBuilder.create(config);
        return jsonb.toJson(jasons);
    }

    /**
     * PUT method for updating or creating an instance of GenericResource
     *
     * @param content representation for the resource
     */
    @PUT
    @Consumes(MediaType.APPLICATION_XML)
    public void putXml(String content) {
    }
}
