package com.house365.web;

import com.house365.beans.dto.AgentDTO;
import com.house365.beans.dto.DepartmentDTO;
import com.house365.beans.dto.TagDTO;
import com.house365.beans.dto.UserDTO;
import com.house365.service.interfaces.EnterpriseClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Date: 2016/11/29</p>
 *
 * @author XN
 * @version 1.0
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("enterprise")
public class EnterpriseController {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    EnterpriseClient enterpriseClient;

    @RequestMapping(value = "/agent/{method}", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String agent(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                        @RequestParam(value = "secret") String secret, AgentDTO agentDTO) {
        return enterpriseClient.agent(method, corpId, secret, agentDTO);
    }

    @RequestMapping(value = "menu/{method}", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String menu(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                       @RequestParam(value = "secret") String secret, @RequestParam(value = "agentid") String agentId,
                       @RequestParam(value = "button", required = false) String button) {
        return enterpriseClient.menu(method, corpId, secret, agentId, button);
    }

    @RequestMapping(value = "user/{method}", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String user(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                       @RequestParam(value = "secret") String secret, UserDTO user) {
        return enterpriseClient.user(method, corpId, secret, user);
    }

    @RequestMapping(value = "department/{method}", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String department(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                             @RequestParam(value = "secret") String secret, DepartmentDTO department) {
        return enterpriseClient.department(method, corpId, secret, department);
    }

    @RequestMapping(value = "tag/{method}", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String tag(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                      @RequestParam(value = "secret") String secret, TagDTO tag) {
        return enterpriseClient.tag(method, corpId, secret, tag);
    }

    @RequestMapping(value = "batch/{method}", method = RequestMethod.POST)
    @ResponseBody
    public String batch(@PathVariable("method") String method, @RequestParam(value = "corpId") String corpId,
                        @RequestParam(value = "secret") String secret, @RequestParam(value = "media_id") String mediaId,
                        @RequestParam(value = "callback") String callback, @RequestParam(value = "jobid") String jobId) {
        return enterpriseClient.batch(method, corpId, secret, mediaId, callback, jobId);
    }
}
