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

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.mall.entity.MallLogisticsCompany;
import com.jeesharp.business.modules.mall.mapper.MallLogisticsCompanyMapper;
import com.jeesharp.business.modules.mall.service.MallLogisticsCompanyService;
import com.jeesharp.business.modules.common.constants.PlatformTenantConstants;
import com.jeesharp.business.modules.mall.vo.MallLogisticsCompanyQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 物流公司领域服务：平台统一维护主数据，启用列表与发货校验固定查平台租户。
 *
 * @author jeesharp
 * @since 2026-06-30
 */
@Service
@Transactional(readOnly = true)
public class MallLogisticsCompanyServiceImpl extends CrudService<MallLogisticsCompanyMapper, MallLogisticsCompany, MallLogisticsCompanyQueryVO> implements MallLogisticsCompanyService {

    @Override
    @Transactional(readOnly = false)
    public void createCompany(MallLogisticsCompany entity) {
        save(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateCompany(MallLogisticsCompany entity) {
        update(entity);
    }

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

    @Override
    public MallLogisticsCompany getPlatformCompany(String id) {
        if (StrUtil.isBlank(id)) {
            return null;
        }
        return getBaseMapper().selectByIdAndTenantCode(
            PlatformTenantConstants.PLATFORM_TENANT_CODE, id.trim());
    }
}
