package com.viettel.campaign.web.rest;

import com.viettel.campaign.service.AgentsService;
import com.viettel.campaign.web.dto.CampaignAgentDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignAgentRequestDTO;
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;
import java.util.List;

@RestController
@RequestMapping("/ipcc/agents")
@CrossOrigin(origins = "*")
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> listAgentByCompanySiteId(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId) {
        ResultDTO result = agentsService.getAllAgentByCompanySiteId(page, pageSize, companySiteId);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

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

    @PostMapping("/createCampaignAgent")
    @ResponseBody
    public ResultDTO createCampaignAgent(@RequestBody @Valid CampaignAgentDTO campaignAgentDTO) {
        ResultDTO result = new ResultDTO();
        result = agentsService.createCampaignAgent(campaignAgentDTO);
        return result;
    }

    @PostMapping("/deleteCampaignAgent")
    @ResponseBody
    public ResultDTO deleteCampaignAgentById(@RequestBody @Valid List<Long> campaignAgentId) {
        ResultDTO result = new ResultDTO();
        result = agentsService.deleteCampaignAgentById(campaignAgentId);
        return result;
    }

    @GetMapping("/searchCampaignAgent")
    @ResponseBody
    public ResponseEntity<ResultDTO> searchCampaignAgent(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("userName") String userName, @RequestParam("fullName") String fullName) {
        ResultDTO result = agentsService.searchCampaignAgentByName(page, pageSize, companySiteId, userName, fullName);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @PostMapping("/createMultipleCampaignAgent")
    @ResponseBody
    public ResultDTO createMultipleCampaignAgent(@RequestBody @Valid CampaignAgentRequestDTO campaignAgentRequestDTO) {
        ResultDTO result = new ResultDTO();
        result = agentsService.createMultipleCampaignAgent(campaignAgentRequestDTO);
        return result;
    }
}
