package com.coding4people.mosquitoreport.api.controllers;

import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.hibernate.validator.constraints.NotEmpty;

import com.coding4people.mosquitoreport.api.models.User;
import com.coding4people.mosquitoreport.api.repositories.UserRepository;

@Path("/profile")
public class ProfileController {
    @Inject UserRepository userRepository;
    @Inject User currentUser;

    /**
     * @api {get} /profile Show user profile details
     * @apiGroup User
     * 
     * @apiParam {String} TODO
     *
     * @apiParamExample {json} Request-Example:
     *     {
     *      "TODO": "TODO"
     *     }
     * 
     * @apiSuccessExample Success-Headers:
     *     HTTP/1.1 200 OK
     *
     * @apiSuccessExample Success-Response:
     *     {
     *       "TODO": "TODO"
     *     }
     */
    @GET
    @Produces("application/json;charset=UTF-8")
    public User get() {
        return currentUser;
    }
    
    @POST
    @Consumes("application/json")
    @Produces("application/json;charset=UTF-8")
    public User post(@Valid ProfilePostInput input) {
        currentUser.setFirstname(input.getFirstname());
        currentUser.setLastname(input.getLastname());
        currentUser.setLocation(input.getLocation());
        currentUser.setFacebookurl(input.getFacebookurl());
        currentUser.setTwitter(input.getTwitter());
        
        userRepository.save(currentUser);
        
        return currentUser;
    }

    public static class ProfilePostInput {
        @NotNull
        @NotEmpty
        private String firstname;
        
        private String lastname;
        
        private String location;
        
        private String facebookurl;
        
        private String twitter;

        public String getFirstname() {
            return firstname;
        }

        public void setFirstname(String firstname) {
            this.firstname = firstname;
        }

        public String getLastname() {
            return lastname;
        }

        public void setLastname(String lastname) {
            this.lastname = lastname;
        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getFacebookurl() {
            return facebookurl;
        }

        public void setFacebookurl(String facebookurl) {
            this.facebookurl = facebookurl;
        }

        public String getTwitter() {
            return twitter;
        }

        public void setTwitter(String twitter) {
            this.twitter = twitter;
        }
    }
}

@@ -730,27 +730,67 @@
 @api
-Param %7BString%7D TODO
+SuccessExample Success-Headers:%0D%0A     *     HTTP/1.1 200 OK
 %0D%0A  
@@ -810,21 +810,23 @@
 @api
-Param
+Success
 Example 
 %7Bjso
@@ -825,29 +825,23 @@
 ple 
-%7Bjson%7D Request-Exampl
+Success-Respons
 e:%0D%0A
@@ -870,36 +870,96 @@
     
-%22TODO%22: %22TODO%22%0D%0A     *     %7D
+ %22guid%22: %22f68079be-2c23-41dd-9ca2-0cc6aa368c5a%22,%0D%0A     *       %22email%22: %22test@test.org%22,
 %0D%0A  
@@ -967,88 +967,115 @@
   * 
-%0D%0A
      
-* @apiSuccessExample Success-Headers:%0D%0A     *     HTTP/1.1 200 OK
+ %22firstname%22: %22Rog%C3%A9rio%22,%0D%0A     *       %22lastname%22: %22Yokomizo%22,%0D%0A     *       %22location%22: null,
 %0D%0A     *
 %0D%0A  
@@ -1074,96 +1074,107 @@
    *
-%0D%0A
+ 
      
-* @apiSuccessExample Success-Response:%0D%0A     *     %7B%0D%0A     *       %22TODO%22: %22TODO%22
+ %22facebookurl%22: null,%0D%0A     *       %22twitter%22: null,%0D%0A     *       %22profilepictureguid%22: null
 %0D%0A  

Document profile controller