package cn.reghao.oss.store.rpc.disk;

import cn.reghao.oss.api.dto.DeleteFile;
import cn.reghao.oss.api.iface.disk.TrashService;
import cn.reghao.oss.store.db.mapper.FileMetaMapper;
import cn.reghao.oss.store.service.PutObjectService;
import cn.reghao.jutil.jdk.db.Page;
import cn.reghao.jutil.jdk.db.PageList;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author reghao
 * @date 2023-05-18 20:39:45
 */
@Slf4j
@DubboService
@Service
public class TrashServiceImpl implements TrashService {
    private PutObjectService putObjectService;
    private final FileMetaMapper fileMetaMapper;
    private final int pageSize = 10;

    public TrashServiceImpl(PutObjectService putObjectService, FileMetaMapper fileMetaMapper) {
        this.fileMetaMapper = fileMetaMapper;
        this.putObjectService = putObjectService;
    }

    @Override
    public PageList<DeleteFile> getTrashList(int pageNumber, int pageSize) {
        int total = fileMetaMapper.countDeletedFiles();
        Page page = new Page(pageNumber, pageSize);
        List<DeleteFile> list = fileMetaMapper.findDeletedFileByPage(page);
        PageList<DeleteFile> pageList = PageList.pageList(pageNumber, pageSize, total, list);
        return pageList;
    }
}
