package com.yami.shop.distribution.comment.listener;

import com.yami.shop.bean.event.OpenShopInitEvent;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.distribution.comment.model.DistributionBasicSet;
import com.yami.shop.distribution.comment.service.DistributionBasicSetService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 开店初始化事件
 */
@Slf4j
@Component("distributionOpenShopInitListener")
@AllArgsConstructor
public class OpenShopInitListener {

    private final DistributionBasicSetService distributionBasicSetService;

    @EventListener(OpenShopInitEvent.class)
    public void OpenShopInitDistributionSetEvent(OpenShopInitEvent event) {
        ShopDetail shopDetail = event.getShopDetail();
        // 添加设置
        DistributionBasicSet distributionBasicSet = new DistributionBasicSet();
        // 分销互购
        distributionBasicSet.setParallelDeal(0);
        // 分销自购
        distributionBasicSet.setOwnBuyAward(0);
        // 会员价购买
        distributionBasicSet.setVipBuyAward(0);
        // 分销总开关
        distributionBasicSet.setDistributionSwitch(1);

        // 0表示为系统设置
        distributionBasicSet.setModifierId(0L);
        distributionBasicSet.setUpdateTime(new Date());
        distributionBasicSet.setShopId(shopDetail.getShopId());
        distributionBasicSet.setShopName(shopDetail.getShopName());
        distributionBasicSetService.save(distributionBasicSet);
    }
}
