package com.fos.demo.shop.api;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fos.core.api.RequestBean;
import com.fos.core.api.ResponseBean;
import com.fos.core.base.BaseBean;
import com.fos.core.base.GenericBean;
import com.fos.core.conf.GConstants;
//import com.fos.modules.shop.entity.ShopEntity;
//import com.fos.modules.shop.service.ShopService;
//import com.fos.modules.user.bean.UserFindByCodeBean;
//import com.fos.modules.user.entity.UserEntity;
//import com.fos.modules.user.service.UserService;

@Controller
@RequestMapping(value = "/demo/api/shop")
public class DemoShopController {

//    @Autowired
//    private ShopService shopService;
//    
//    @Autowired
//    private UserService userService;
    
    @ResponseBody
    @RequestMapping(value = "/getShop")
    public ResponseBean getShop(HttpServletRequest request, 
            @Valid RequestBean requestBean, BindingResult errors){
        ResponseBean responseBean = new ResponseBean();
//        String message = requestBean.getValidateMessage(errors);
//        if(message == null){
//            
//            BaseBean baseBean = requestBean.getObjectBean(BaseBean.class);
//            
//            ShopEntity shopEntity = shopService.findByCode(baseBean.getShopCode());
//            
//            responseBean.setData(shopEntity);
//            responseBean.setMessage(GConstants.OK);
//            responseBean.setStatus(GConstants.STATUS_CODE_2000);
//            return responseBean;
//        }
//        responseBean.setMessage(message);
//        responseBean.setStatus(GConstants.STATUS_CODE_4001);
        return responseBean;
    }
    @ResponseBody
    @RequestMapping(value = "/getUserId")
    public ResponseBean getUserId(HttpServletRequest request, 
            @Valid RequestBean requestBean, BindingResult errors){
        ResponseBean responseBean = new ResponseBean();
//        String message = requestBean.getValidateMessage(errors);
//        if(message == null){
//            
//            UserFindByCodeBean genericBean = requestBean.getObjectBean(UserFindByCodeBean.class);
//            
//            long id = userService.getUserIdByCode(genericBean.getUserCode());
//            
//            responseBean.setData(id);
//            responseBean.setMessage(GConstants.OK);
//            responseBean.setStatus(GConstants.STATUS_CODE_2000);
//            return responseBean;
//        }
//        responseBean.setMessage(message);
//        responseBean.setStatus(GConstants.STATUS_CODE_4001);
        return responseBean;
    }
    @ResponseBody
    @RequestMapping(value = "/getUser")
    public ResponseBean getUser(HttpServletRequest request, 
            @Valid RequestBean requestBean, BindingResult errors){
        ResponseBean responseBean = new ResponseBean();
//        String message = requestBean.getValidateMessage(errors);
//        if(message == null){
//            
//            UserFindByCodeBean genericBean = requestBean.getObjectBean(UserFindByCodeBean.class);
//            
//            UserEntity userEntity = userService.findByCode(genericBean.getUserCode());
//            responseBean.setData(userEntity);
//            responseBean.setMessage(GConstants.OK);
//            responseBean.setStatus(GConstants.STATUS_CODE_2000);
//            return responseBean;
//        }
//        responseBean.setMessage(message);
//        responseBean.setStatus(GConstants.STATUS_CODE_4001);
        return responseBean;
    }
}
