package me.chyxion.tigon.shiro.controller;

import me.chyxion.tigon.format.annotation.EmptyToNull;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author chyxion <br>
 * chyxion@163.com <br>
 * May 31, 2015 3:53:04 PM
 */
@Validated
@Controller
public class SiteController {

    @RequestMapping("/")
    public void index() {
        
    }

    @RequestMapping("/v")
    public String index(@RequestParam("v")
        // @EmptyToNull
        String validate) {
        return validate;
    }

    @RequestMapping("/raw")
    public Map<String, Object> raw() {
        Map<String, Object> mapRaw = new HashMap<String, Object>();
        mapRaw.put("data", "Hello!");
        return mapRaw;
    }

    @RequestMapping("/int")
    public int integer() {
        return 99;
    }

    @RequestMapping("/post")
    public String post(@Validated Form form) {
        return form.getId();
    }
    
    public static class Form {
        @NotBlank
        private String id;
        @NotBlank
        private String name;
        @EmptyToNull
        private String gender;

        /**
         * @return the id
         */
        public String getId() {
            return id;
        }

        /**
         * @param id the id to set
         */
        public void setId(String id) {
            this.id = id;
        }

        /**
         * @return the name
         */
        public String getName() {
            return name;
        }

        /**
         * @param name the name to set
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * @return the gender
         */
        public String getGender() {
            return gender;
        }

        /**
         * @param gender the gender to set
         */
        public void setGender(String gender) {
            this.gender = gender;
        }
    }
}
