package com.cool.store.dao.order;

import com.cool.store.entity.order.PreAllocationRecordDO;
import com.cool.store.mapper.order.PreAllocationRecordMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class PreAllocationRecordDAO {

    private final PreAllocationRecordMapper preAllocationRecordMapper;

    public boolean insertSelective(PreAllocationRecordDO record) {
        return preAllocationRecordMapper.insertSelective(record) > 0;
    }

    public boolean updateByPrimaryKeySelective(PreAllocationRecordDO record) {
        return preAllocationRecordMapper.updateByPrimaryKeySelective(record) > 0;
    }

    public PreAllocationRecordDO getById(Long id) {
        return preAllocationRecordMapper.getById(id);
    }

    public List<PreAllocationRecordDO> queryPageByOrderId(Long orderId) {
        return preAllocationRecordMapper.queryPageByOrderId(orderId);
    }

    public List<PreAllocationRecordDO> queryPageByShopId(Long shopId) {
        return preAllocationRecordMapper.queryPageByShopId(shopId);
    }

    public PreAllocationRecordDO queryPageByShopIdAndExpenseType(Long shopId,String expenseType) {
        return preAllocationRecordMapper.queryPageByShopIdAndExpenseType(shopId,expenseType);
    }

    public PreAllocationRecordDO queryPageByPayNo(String payNo) {
        return preAllocationRecordMapper.queryPageByPayNo(payNo);
    }

    public boolean updateStatus(Long id, Integer status) {
        return preAllocationRecordMapper.updateStatus(id, status) > 0;
    }

    public boolean deleteByShopId(Long shopId) {
        return preAllocationRecordMapper.deleteByShopId(shopId) > 0;
    }

    public boolean updateByPayNoList(List<String> payNoList,Integer status) {
        return preAllocationRecordMapper.updateByPayNoList(payNoList,status)>0;
    }

    public boolean insertBatch(List<PreAllocationRecordDO> list) {
        return preAllocationRecordMapper.insertBatch(list) > 0;
    }

    public boolean updateBatch(List<PreAllocationRecordDO> list) {
        return preAllocationRecordMapper.updateBatch(list) > 0;
    }

    public boolean batchUpdateEditableFields(List<PreAllocationRecordDO> list) {
        if (list == null || list.isEmpty()) {
            return false;
        }
        return preAllocationRecordMapper.batchUpdateEditableFields(list) > 0;
    }

    public boolean updateByOrderId(Long orderId) {
        return preAllocationRecordMapper.updateByOrderId(orderId) > 0;
    }

    public boolean deleteByIdsNotPaid(List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return false;
        }
        return preAllocationRecordMapper.deleteByIdsNotPaid(ids) > 0;
    }

    /**
     * 软删除
     */
    public boolean softDeleteById(Long id) {
        return preAllocationRecordMapper.softDeleteById(id) > 0;
    }

    /**
     * 批量软删除
     */
    public boolean softDeleteByIds(List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return false;
        }
        return preAllocationRecordMapper.softDeleteByIds(ids) > 0;
    }
}