package com.viettel.campaign.service.impl;

import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.repository.ccms_full.TicketRepository;
import com.viettel.campaign.service.TicketService;
import com.viettel.campaign.web.dto.TicketDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class TicketServiceImpl implements TicketService {

    @Autowired
    TicketRepository ticketRepository;

     @Override
     @Transactional(DataSourceQualify.CCMS_FULL)
    public Map getHistory(int page, int pageSize, String sort, String customerId) {
        Map result = new HashMap();
        List<TicketDTO> lst = new ArrayList<>();

        lst = ticketRepository.getHistory(customerId, PageRequest.of(page, pageSize, Sort.by(sort)));

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

        return result;
    }
}
