package com.jeesharp.business.modules.mall.service.impl;

import com.jeesharp.business.modules.mall.entity.MallAddPurchase;
import com.jeesharp.business.modules.mall.mapper.MallAddPurchaseMapper;
import com.jeesharp.business.modules.mall.service.MallAddPurchaseService;
import com.jeesharp.business.modules.mall.vo.MallAddPurchaseQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 加价购配置 Service 实现类
 */
@Service
@Transactional(readOnly = true)
public class MallAddPurchaseServiceImpl extends CrudService<MallAddPurchaseMapper, MallAddPurchase, MallAddPurchaseQueryVO> implements MallAddPurchaseService {

    private static final int ENABLED_STATUS = 1;
    private static final String IDS_SEPARATOR = ",";

    @Override
    @Transactional(readOnly = false)
    public void createAddPurchase(MallAddPurchase entity) {
        save(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateAddPurchase(MallAddPurchase entity) {
        update(entity);
    }

    @Override
    public List<MallAddPurchase> getAddPurchaseOptions(String mainSkuId) {
        MallAddPurchaseQueryVO query = new MallAddPurchaseQueryVO();
        query.setMainSkuId(mainSkuId);
        query.setStatus(ENABLED_STATUS);
        return findList(query);
    }

    @Override
    public List<MallAddPurchase> getAvailableAddPurchases() {
        MallAddPurchaseQueryVO query = new MallAddPurchaseQueryVO();
        query.setStatus(ENABLED_STATUS);
        return findList(query);
    }
}
