package cn.iselab.mooctest.user.rpc;

import cn.iselab.mooctest.rpc.user.api.IntegralService;
import cn.iselab.mooctest.rpc.user.data.AddIntegralDTO;
import cn.iselab.mooctest.rpc.user.data.IntegralCaughtDTO;
import cn.iselab.mooctest.rpc.user.data.UserIntegralDTO;
import cn.iselab.mooctest.user.web.logic.IntegralLogic;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author ROKG
 * @Description
 * @Date: Created in 下午12:09 2018/2/14
 * @Modified By:
 */
@Service(version = "1.0.0")
@Component
public class IntegralRPC implements IntegralService {

    @Autowired
    IntegralLogic integralLogic;

    /**
     * save user caught integral
     * @param dto
     * @return medalTO
     */
    @Override
    public IntegralCaughtDTO saveIntegralCaught(IntegralCaughtDTO dto){
        return integralLogic.saveIntegralCaught(dto);
    }

    /**
     * get user's integral by time
     * @param userId user's id
     * @param startTime
     * @param endTime
     * @return medalTO
     */
    @Override
    public List<IntegralCaughtDTO> getIntegralCaughts(long userId, long startTime, long endTime){
        return integralLogic.getIntegralCaughts(userId,startTime,endTime);
    }

    /**
     * get user's integral ranking list
     * @param keyword search for single task
     * @return medalTO
     */
    @Override
    public List<UserIntegralDTO> getUserIntegrals(String keyword){
        return integralLogic.getUserIntegrals(keyword);
    }

    /**
     * check if user's event can bring integral
     * @param dto
     * @return
     */
    @Override
    public boolean checkIntegral(AddIntegralDTO dto){
        return integralLogic.addIntegral(dto);
    }

    /**
     * get user's integral by userId
     * @param userId
     * @return
     */
    @Override
    public UserIntegralDTO getUserIntegral(Long userId){
        return integralLogic.getUserIntegral(userId);
    }

    @Override
    public List<IntegralCaughtDTO> getUserIntegralRecord(long userId, long type, String source) {
        return integralLogic.getUserIntegralRecord(userId, type, source);
    }
}
