package com.cool.store.dao.order;

import com.cool.store.dto.fees.ExpenseTypeAmountDTO;
import com.cool.store.entity.order.StoreOrderOptionSnapshotDO;
import com.cool.store.mapper.order.StoreOrderOptionSnapshotMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Repository
@RequiredArgsConstructor
public class StoreOrderOptionSnapshotDAO {

    private final StoreOrderOptionSnapshotMapper mapper;

    public boolean insertBatch(List<StoreOrderOptionSnapshotDO> list) {
        if (CollectionUtils.isEmpty(list)) {
            return false;
        }
        return mapper.insertBatch(list) > 0;
    }

    public List<StoreOrderOptionSnapshotDO> listByOrderId(Long orderId) {
        if (orderId == null) {
            return Collections.emptyList();
        }
        return mapper.listByOrderId(orderId);
    }

    public boolean deleteByOrderId(Long orderId) {
        if (orderId == null) {
            return false;
        }
        return mapper.deleteByOrderId(orderId) > 0;
    }

    public boolean updateSelective(StoreOrderOptionSnapshotDO snapshotDO) {
        if (snapshotDO == null || snapshotDO.getId() == null) {
            return false;
        }
        return mapper.updateByPrimaryKeySelective(snapshotDO) > 0;
    }

    public void batchUpdateQuantityAndAmount(@Param("list") List<StoreOrderOptionSnapshotDO> list){
        if (CollectionUtils.isEmpty(list)){
            return;
        }
        mapper.batchUpdateQuantityAndAmount(list);
    }

    public List<ExpenseTypeAmountDTO> getExpenseTypeAmountByOrderId(Long orderId) {
        if (orderId == null) {
            return Collections.emptyList();
        }
        return mapper.getExpenseTypeAmountByOrderId(orderId);
    }
}
