package com.cool.store.dao;

import com.cool.store.constants.CommonConstants;
import com.cool.store.dto.pre.fry.DailyFryCountDTO;
import com.cool.store.dto.pre.fry.PreFryRecordQueryDTO;
import com.cool.store.dto.pre.fry.PreFryRecordsDTO;
import com.cool.store.dto.pre.fry.ViolationDTO;
import com.cool.store.entity.PreFryRecordsDO;
import com.cool.store.mapper.PreFryRecordsMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

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

/**
 * @Author suzhuhong
 * @Date 2025/6/20 19:13
 * @Version 1.0
 */
@Repository
public class PreFryRecordsDAO {

    @Resource
    private PreFryRecordsMapper preFryRecordsMapper;

    public int insert(PreFryRecordsDO record) {
        if (Objects.isNull(record)) {
            return CommonConstants.ZERO;
        }
        return preFryRecordsMapper.insertSelective(record);
    }



    public int batchInsert(List<PreFryRecordsDO> records) {
        if (CollectionUtils.isEmpty(records)) {
            return CommonConstants.ZERO;
        }
        return preFryRecordsMapper.batchInsert(records);
    }



    public PreFryRecordsDO queryById(Long id) {
        if (id == null) {
            return null;
        }
        return preFryRecordsMapper.selectByPrimaryKey(id);
    }


    public int updateByPrimaryKeySelective(PreFryRecordsDO preFryRecordsDO) {
        return preFryRecordsMapper.updateByPrimaryKeySelective(preFryRecordsDO);
    }

    public List<PreFryRecordsDO> queryByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }
        return preFryRecordsMapper.selectByIds(ids);
    }


    public int batchUpdateStageByIds( List<Long> ids,
                              Integer currentStage){
        if (CollectionUtils.isEmpty(ids)) {
            return CommonConstants.ZERO;
        }
        return preFryRecordsMapper.batchUpdateStageByIds(ids,currentStage);
    }

    public List<PreFryRecordsDO> selectByStoreAndDateStage(String storeCode,
                                                           Integer applyType,  String queryDate){
        if (StringUtils.isBlank(storeCode)) {
            return null;
        }
        return preFryRecordsMapper.selectByStoreAndDateStage(storeCode,applyType,queryDate);
    }

    public List<DailyFryCountDTO> selectDailyFryCountInCurrentMonth(String storeCode,Long time) {
        if (StringUtils.isEmpty(storeCode)) {
            return null;
        }
        return preFryRecordsMapper.selectDailyFryCountInCurrentMonth(storeCode,time);
    }


    public List<PreFryRecordsDTO> selectByQueryDTO(PreFryRecordQueryDTO dto) {
        return preFryRecordsMapper.selectByQueryDTO(dto);
    }

    public void batchUpdateViolation(List<ViolationDTO> violationList) {
        if (CollectionUtils.isEmpty(violationList)){
            return;
        }
        preFryRecordsMapper.batchUpdateViolation(violationList);
    }


}
