package com.cool.store.service.impl;

import com.cool.store.dao.NewStoreOpeningDAO;
import com.cool.store.dao.ShopStageInfoDAO;
import com.cool.store.entity.NewStoreOpeningDO;
import com.cool.store.entity.ShopStageInfoDO;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.request.NewStoreOpeningRequest;
import com.cool.store.service.NewStoreOpeningService;
import com.cool.store.vo.NewStoreOpeningVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

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

/**
 * @author byd
 * @date 2024-04-24 14:32
 */
@Service
public class NewStoreOpeningServiceImpl implements NewStoreOpeningService {

    @Resource
    private NewStoreOpeningDAO newStoreOpeningDAO;

    @Resource
    private ShopStageInfoDAO shopStageInfoDAO;

    @Override
    public List<NewStoreOpeningVO> storeTodoList(Long shopId) {
        List<NewStoreOpeningDO> storeOpeningDOList = newStoreOpeningDAO.storeTodoList(shopId);
        List<NewStoreOpeningVO> resultList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(storeOpeningDOList)){
            storeOpeningDOList.forEach(storeOpeningDO -> {
                NewStoreOpeningVO newStoreOpeningVO = new NewStoreOpeningVO();
                newStoreOpeningVO.setId(storeOpeningDO.getId());
                newStoreOpeningVO.setShopId(storeOpeningDO.getShopId());
                newStoreOpeningVO.setCompletionTime(storeOpeningDO.getCompletionTime());
                newStoreOpeningVO.setTodoItem(storeOpeningDO.getTodoItem());
                resultList.add(newStoreOpeningVO);
            });
        }
        return resultList;
    }

    @Override
    public void addStoreTodo(NewStoreOpeningRequest newStoreOpeningRequest) {
        // 判断是否可以添加
        ShopStageInfoDO shopStageInfoDO = shopStageInfoDAO.getShopSubStageInfo(newStoreOpeningRequest.getShopId(), ShopSubStageEnum.SHOP_STAGE_17);

//        if(shopStageInfoDO != null && shopStageInfoDO.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_171.getShopSubStageStatus())){
//            throw new ServiceException("该店铺已经完成试运营，不能再添加待办事项");
//        }

        NewStoreOpeningDO newStoreOpeningDO = new NewStoreOpeningDO();
        newStoreOpeningDO.setShopId(newStoreOpeningRequest.getShopId());
        newStoreOpeningDO.setTodoItem(newStoreOpeningRequest.getTodoItem());
        newStoreOpeningDO.setCompletionTime(newStoreOpeningRequest.getCompletionTime());
        newStoreOpeningDAO.insertSelective(newStoreOpeningDO);
    }

    @Override
    public void removeStoreTodo(Long id) {
        newStoreOpeningDAO.deleteByPrimaryKey(id);
    }
}
