package com.viettel.campaign.web.rest;

import com.viettel.campaign.service.AgentsService;
import com.viettel.campaign.web.dto.CampaignAgentsDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/ipcc/agents")
@CrossOrigin
public class AgentsController {

    private static final Logger logger = LoggerFactory.getLogger(CampaignController.class);

    @Autowired
    AgentsService agentsService;

    @GetMapping("/getAgentsById")
    @ResponseBody
    public ResponseEntity<ResultDTO> getAgentsById(@RequestParam("agentId") String agentId) {
        ResultDTO result = agentsService.getAgentsByAgentId(agentId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping("/findAll")
    @ResponseBody
    public ResponseEntity<ResultDTO> listAgentsByCompanySiteId(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId) {
        ResultDTO result = agentsService.getAllAgentsByCompanySiteId(page, pageSize, companySiteId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping("/findAllSelected")
    @ResponseBody
    public ResponseEntity<ResultDTO> listAgentsSelectedByCompanySiteId(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("campaignId") Long campaignId) {
        ResultDTO result = agentsService.getAllAgentsSelectedByCompanySiteId(page, pageSize, companySiteId, campaignId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @PostMapping("/createCampaignAgents")
    @ResponseBody
    public ResultDTO createCustomerList(@RequestBody @Valid CampaignAgentsDTO campaignAgentsDTO) {
        ResultDTO result = new ResultDTO();
        result = agentsService.createCampaignAgents(campaignAgentsDTO);
        return result;
    }
}
