package cn.edu.whu.boot.allocation.services.impl;

import cn.edu.whu.boot.allocation.entities.Image;
import cn.edu.whu.boot.allocation.mapper.ImageMapper;
import cn.edu.whu.boot.allocation.services.ImageService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class ImageServiceImpl implements ImageService {

    private final ImageMapper imageMapper;

    public ImageServiceImpl(ImageMapper imageMapper) {
        this.imageMapper = imageMapper;
    }

    @Override
    public Optional<String> findFilenameById(int id) {
        return Optional.ofNullable(imageMapper.findFilenameById(id));
    }

    @Override
    public int countByFilename(String filename)
    {
        return imageMapper.countByFilename(filename);
    }

    @Override
    public List<String> findFilenamesInIds(List<Integer> ids) {
        return imageMapper.findFilenamesByIds(ids);
    }

    @Override
    public List<Image> findByTaskId(int taskId) {
        return imageMapper.findByTaskId(taskId);
    }

    @Override
    public int countByTaskId(int taskId) {
        return imageMapper.countByTaskId(taskId);
    }

    @Override
    public List<Map<String, Object>> findByTaskIdPaginated(int taskId, int page, int count) {
        return imageMapper.findByTaskIdPaginated(taskId, page, count);
    }

    @Override
    public int insert(Image image) {
        return imageMapper.insert(image);
    }

    @Override
    public void deleteInIds(List<Integer> ids) {
        imageMapper.deleteInIds(ids);
    }
}