package com.YuyeTech.TPlat.service.impl;

import com.YuyeTech.TPlat.dataobject.SignIn;
import com.YuyeTech.TPlat.dataobject.SignInReward;
import com.YuyeTech.TPlat.dataobject.UserWallets;
import com.YuyeTech.TPlat.enums.ResultEnum;
import com.YuyeTech.TPlat.exception.UserException;
import com.YuyeTech.TPlat.repository.SignInRepository;
import com.YuyeTech.TPlat.repository.SignInRewardRepository;
import com.YuyeTech.TPlat.repository.UserWalletsRepository;
import com.YuyeTech.TPlat.service.SignInService;
import com.YuyeTech.TPlat.service.UserWalletsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 用户信息
 *
 * @author:slambb
 * @date:2021/8/5
 */
@Service
public class SignInServiceImpl implements SignInService {

    @Autowired
    private SignInRepository signInRepository;

    @Autowired
    private SignInRewardRepository signInRewardRepository;

    @Override
    public SignIn findByUserId(String userId) {
        return signInRepository.findByUserId(userId).orElse(null);
    }

    @Override
    public void addSignIn(SignIn signIn) {
        signInRepository.save(signIn);
    }


    @Override
    public SignInReward getSignInRewardByDays(Integer days) {
        return signInRewardRepository.findByDays(days).orElse(null);
    }

    @Override
    public List<SignInReward> getSignInRewardList() {
        return signInRewardRepository.findAll(Sort.by(Sort.Direction.ASC,"days"));
    }
}

