package com.viettel.campaign.web.rest;

import com.viettel.campaign.model.ApParam;
import com.viettel.campaign.service.ApParamService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/ipcc/apParam")
public class ApParamController {

    private static final Logger LOGGER = Logger.getLogger(CustomerController.class);

    @Autowired(required = true)
    ApParamService apParamService;

    @GetMapping(path = "/findAlls")
    @ResponseBody
    public ResponseEntity listAllCustomer(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort) {
        Iterable<ApParam> listCustomer = apParamService.getAllParams(page, pageSize, sort);
        if (listCustomer == null) {
            return new ResponseEntity(HttpStatus.NO_CONTENT);
        }
        return new ResponseEntity(listCustomer.iterator(), HttpStatus.OK);
    }

    @PostMapping(path = "/findByName")
    @ResponseBody
    public ResponseEntity searchParamByName(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam(name = "parName") String parName) {
        List<ApParam> lst = apParamService.getParamByName(page, pageSize, sort, parName);
        if (lst.isEmpty())
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);

        return new ResponseEntity(lst, HttpStatus.OK);
    }
}
