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

import com.jeesharp.business.modules.mall.entity.MallTag;
import com.jeesharp.business.modules.mall.enums.MallTagTypeEnum;
import com.jeesharp.business.modules.mall.mapper.MallTagMapper;
import com.jeesharp.business.modules.mall.service.MallTagService;
import com.jeesharp.business.modules.common.constants.PlatformTenantConstants;
import com.jeesharp.business.modules.mall.vo.MallTagQueryVO;
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
@Transactional(readOnly = true)
public class MallTagServiceImpl extends CrudService<MallTagMapper, MallTag, MallTagQueryVO> implements MallTagService {

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

    @Override
    @Transactional(readOnly = false)
    public void createTag(MallTag entity) {
        if (entity.getTagType() == null) {
            entity.setTagType(MallTagTypeEnum.PRODUCT.getValue());
        }
        save(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateTag(MallTag entity) {
        update(entity);
    }

    @Override
    public List<MallTag> listEnabledTags() {
        return listPlatformEnabledForPublish();
    }

    @Override
    public List<MallTag> listPlatformEnabledForPublish() {
        return getBaseMapper().selectEnabledByTenantCode(PlatformTenantConstants.PLATFORM_TENANT_CODE);
    }
}
