package shop.alien.store.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import shop.alien.entity.store.LifeImg;
import shop.alien.mapper.LifeImgMapper;
import shop.alien.store.service.LifeImgService;

import java.util.List;

/**
 * 反馈图片 Service实现类
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class LifeImgServiceImpl extends ServiceImpl<LifeImgMapper, LifeImg> implements LifeImgService {

    private final LifeImgMapper lifeImgMapper;

    @Override
    public List<LifeImg> getByFeedbackId(Integer feedbackId) {
        return lifeImgMapper.selectByFeedbackId(feedbackId);
    }

    @Override
    public boolean batchSave(List<LifeImg> imgList) {
        if (imgList == null || imgList.isEmpty()) {
            return false;
        }
        // 确保每个附件都有上传时间
        imgList.forEach(item -> {
            if (item.getUploadTime() == null) {
                item.setUploadTime(new java.util.Date());
            }
        });
        return lifeImgMapper.batchInsert(imgList) > 0;
    }

    @Override
    public boolean removeByFeedbackId(Integer feedbackId) {
        return lifeImgMapper.deleteByFeedbackId(feedbackId) > 0;
    }

    @Override
    public List<String> getImgUrlsByFeedbackId(Integer feedbackId) {
        return lifeImgMapper.selectImgUrlsByFeedbackId(feedbackId);
    }

    @Override
    public List<String> getVideoUrlsByFeedbackId(Integer feedbackId) {
        return lifeImgMapper.selectVideoUrlsByFeedbackId(feedbackId);
    }
}
