package com.cool.store.dao;

import com.cool.store.dto.notice.NoticeDTO;
import com.cool.store.entity.MessageTemplateDO;
import com.cool.store.mapper.MessageTemplateMapper;
import com.cool.store.request.notice.MessageTemplateQueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

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

/**
 * @Author suzhuhong
 * @Date 2025/7/25 9:40
 * @Version 1.0
 */
@Slf4j
@Repository
public class MessageTemplateDAO {

    @Resource
    private MessageTemplateMapper messageTemplateMapper;


    public int insert(MessageTemplateDO messageTemplateDO) {
        return messageTemplateMapper.insertSelective(messageTemplateDO);
    }

    public int update(MessageTemplateDO messageTemplateDO) {
        return messageTemplateMapper.updateByPrimaryKeySelective(messageTemplateDO);
    }

    public MessageTemplateDO getById(Long id) {
        return messageTemplateMapper.selectByPrimaryKey(id);
    }

    public List<MessageTemplateDO> getByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return new ArrayList<>();
        }
        return messageTemplateMapper.selectByIds(ids);
    }

    public int updateDeleteStatusBatch(List<Long> ids,String userId) {
        return messageTemplateMapper.updateDeleteStatusBatch(ids,userId);
    }


    public List<NoticeDTO> getMessageTemplateList(MessageTemplateQueryRequest request) {
        return messageTemplateMapper.getMessageTemplateList(request);
    }

    public int batchUpdateStoreInfoAndUserInfo(List<Long> ids,
                                        String storeInfo,
                                        String userInfo,
                                        String userId) {
        if (CollectionUtils.isEmpty(ids)){
            return 0;
        }
        return messageTemplateMapper.batchUpdateStoreInfoAndUserInfo(ids,storeInfo,userInfo,userId);
    }


    public int batchUpdatePublishStatus(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return 0;
        }
        return messageTemplateMapper.batchUpdatePublishStatus(ids);
    }

    public MessageTemplateDO getByKeyword(String keyword) {
        if (keyword == null){
            return null;
        }
        return messageTemplateMapper.getByKeyword(keyword);
    }



}
