package com.sonic.lion.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sonic.lion.dao.GoogleUploadReceiptDao;
import com.sonic.lion.domain.entity.GoogleUploadReceipt;
import com.sonic.lion.service.GoogleUploadReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: code
 * @date: 2025/07/15
 * @Description:
 * @version: 1.0.0
 */
@Service
public class GoogleUploadReceiptServiceImpl implements GoogleUploadReceiptService {

    @Autowired
    private GoogleUploadReceiptDao googleUploadReceiptDao;

    @Override
    public Long save(@NonNull GoogleUploadReceipt googleUploadReceipt) {
        googleUploadReceiptDao.insert(googleUploadReceipt);
        return googleUploadReceipt.getId();
    }

    @Override
    public GoogleUploadReceipt getById(Long id) {
        return googleUploadReceiptDao.selectById(id);
    }

    @Override
    public boolean countRecepit(String receipt) {
        return googleUploadReceiptDao.selectCount(Wrappers.<GoogleUploadReceipt>lambdaQuery().eq(GoogleUploadReceipt::getReceipt, receipt)) > 0;
    }

    @Override
    public int updateProcessed(@NonNull Long id, @NonNull Boolean processed) {
        GoogleUploadReceipt updater = GoogleUploadReceipt.builder()
                .id(id)
                .processed(processed)
                .build();
        return googleUploadReceiptDao.updateById(updater);
    }

    @Override
    public List<GoogleUploadReceipt> list(Boolean processed, LocalDateTime startCreateTime, Integer num) {
        return googleUploadReceiptDao.list(processed, startCreateTime, num);
    }
}
