package com.viettel.campaign.service.impl;

import com.viettel.campaign.dto.CampaignDTO;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.dto.request_dto.CampaignRequestDTO;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.repository.CampaignRepository;
import com.viettel.campaign.service.CampaignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CampaignServiceImpl implements CampaignService {

    @Autowired
    CampaignRepository campaignRepository;

    @Override
    public Map searchCampaignExecute(int page, int pageSize, String sort, String agentId) {
        Map result = new HashMap();
        List<CampaignDTO> lst = new ArrayList<>();

        Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
        lst = campaignRepository.searchCampaignExecute(agentId, pageable);

        result.put("totalItem", lst.size());
        result.put("customers", lst);

        return result;
    }

    @Override
    public ResultDTO search(CampaignRequestDTO requestDto) {
        return campaignRepository.search(requestDto);
    }
}
