package com.jeesharp.business.modules.marketing.tenantExt.service.impl;

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.marketing.tenantExt.entity.MarketingTenantExt;
import com.jeesharp.business.modules.marketing.tenantExt.mapper.MarketingTenantExtMapper;
import com.jeesharp.business.modules.marketing.tenantExt.service.MarketingTenantExtService;
import com.jeesharp.business.modules.marketing.tenantExt.vo.MarketingTenantExtQueryVO;
import com.jeesharp.framework.exception.BizErrorException;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;

/**
 * 店铺营销扩展配置领域服务实现。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@Service
public class MarketingTenantExtServiceImpl extends CrudService<MarketingTenantExtMapper, MarketingTenantExt, MarketingTenantExtQueryVO>
        implements MarketingTenantExtService {

    @Override
    public MarketingTenantExt createMarketingTenantExt(MarketingTenantExt entity) {
        if (StrUtil.isNotBlank(entity.getId())) {
            throw new BizErrorException("新增营销配置不应预置主键");
        }
        getBaseMapper().insert(entity);
        return entity;
    }

    @Override
    public void updateMarketingTenantExt(MarketingTenantExt entity) {
        if (StrUtil.isBlank(entity.getId())) {
            throw new BizErrorException("更新营销配置主键不能为空");
        }
        if (get(entity.getId()) == null) {
            throw new BizErrorException("营销配置不存在");
        }
        getBaseMapper().update(entity);
    }

    @Override
    public MarketingTenantExt getByTenantId(String tenantId) {
        if (StrUtil.isBlank(tenantId)) {
            return null;
        }
        return getBaseMapper().getByTenantId(tenantId);
    }
}
