package cn.iocoder.yudao.module.museum.service.museumpicture;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.MuseumPictureSaveVO;
import cn.iocoder.yudao.module.museum.controller.admin.museumpicture.vo.PicturePageReqVO;
import cn.iocoder.yudao.module.museum.dal.database.museumpicture.MuseumPictureDO;
import cn.iocoder.yudao.module.museum.dal.mysql.museumpicture.MuseumPictureMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public  class MuseumPictureServiceImpl implements MuseumPictureService {

    @Resource
    private MuseumPictureMapper museumPictureMapper;

//    @Override
//    public Integer createMuseumPicture(MuseumPictureSaveVO saveVO){
//        return museumPictureMapper.insert(BeanUtils.toBean(saveVO, MuseumPictureDO.class));
//    }

    @Override
    public Integer createMuseumPicture(MuseumPictureSaveVO saveVO) {
        Integer photoGroupId = saveVO.getGroupId();
        List<String> urls = Collections.singletonList(saveVO.getPictureUrl());

        for (String url : urls) {
            MuseumPictureSaveVO museumPicture = new MuseumPictureSaveVO();
            museumPicture.setGroupId(photoGroupId);
            museumPicture.setPictureUrl(url);
            return museumPictureMapper.insert(BeanUtils.toBean(saveVO, MuseumPictureDO.class));
        }

        return photoGroupId; // 返回照片组ID作为操作成功的标识
    }

    @Override
    public void updateMuseumPicture(MuseumPictureSaveVO saveVO){
        museumPictureMapper.updateMuseumPicture(BeanUtils.toBean(saveVO,MuseumPictureDO.class));
    }

    @Override
    public void deleteMuseumPicture(Integer picture_id){
//      museumPictureMapper.deleteMuseumPicture(picture_id);
        museumPictureMapper.deleteById(picture_id);
    }

    @Override
        public MuseumPictureDO selectMuseumPicture(Integer picture_id){
        return museumPictureMapper.selectMuseumPictureById(picture_id);
    }

    @Override
    public PageResult<MuseumPictureDO> getPicturePage(PicturePageReqVO pageVO) {
        return null;
    }

//    @Override
//    public MuseumPictureDO selectMuseumPictureSet(Integer group_id){
//        return museumPictureMapper.selectMuseumPictureSetById(group_id);
//    }
}

