package shop.alien.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import shop.alien.entity.store.LifeMessageNotDisturb;
import shop.alien.mapper.LifeMessageNotDisturbMapper;
import shop.alien.store.service.LifeMessageNotDisturbService;

/**
 * <p>
 * 消息免打扰 服务实现类
 * </p>
 *
 * @author ssk
 * @since 2025-07-11
 */
@Service
@RequiredArgsConstructor
public class LifeMessageNotDisturbServiceImpl extends ServiceImpl<LifeMessageNotDisturbMapper, LifeMessageNotDisturb> implements LifeMessageNotDisturbService {

    private final LifeMessageNotDisturbMapper lifeMessageNotDisturbMapper;

    @Override
    public boolean notDisturb(String receiverId, String disturbId, int type) {
        if (1 == type) {
            LifeMessageNotDisturb disturb = new LifeMessageNotDisturb();
            disturb.setPhoneId(receiverId);
            disturb.setNotDisturbId(disturbId);
            lifeMessageNotDisturbMapper.insert(disturb);
            return true;
        } else if (2 == type) {
            UpdateWrapper<LifeMessageNotDisturb> wrapper = new UpdateWrapper<>();
            wrapper.eq("phone_id", receiverId);
            wrapper.eq("not_disturb_id", disturbId);
            lifeMessageNotDisturbMapper.delete(wrapper);
            return true;
        }
        return false;
    }
}
