
package com.tmerclub.cloud.user.feign;

import com.tmerclub.cloud.api.coupon.vo.CouponDataVO;
import com.tmerclub.cloud.api.user.feign.PopupFeignClient;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.constant.JumpType;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.user.service.CostPerPopupService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;

/**
 * @author TRACK
 */
@DubboService
public class PopupFeignController implements PopupFeignClient {

    @Autowired
    private CostPerPopupService costPerPopupService;

    @Override
    public ServerResponseEntity<Void> deletePopupProd(Long spuId, Long shopId) {
        costPerPopupService.deletePopupByRelate(spuId, shopId);
        costPerPopupService.deleteLink(spuId, shopId, JumpType.SPU.value(), null);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> deleteLink(Long linkId, Long shopId, String type, List<Long> categoryIds) {
        costPerPopupService.deleteLink(linkId, shopId, type, categoryIds);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> deleteLinkBatch(List<CouponDataVO> couponList) {
        costPerPopupService.deleteLinkBatch(couponList);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> deleteShopLinkBatch(List<Long> shopIds) {
        costPerPopupService.offlineShop(shopIds);
        for (Long shopId : shopIds) {
            costPerPopupService.deleteLink(shopId, Constant.PLATFORM_SHOP_ID, JumpType.SHOP.value(), null);
        }
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> offlineShop(Long shopId) {
        costPerPopupService.offlineShop(Collections.singletonList(shopId));
        costPerPopupService.deleteLink(shopId, Constant.PLATFORM_SHOP_ID, JumpType.SHOP.value(), null);
        return ServerResponseEntity.success();
    }
}
