package com.jeesharp.business.modules.mall.application;

import com.jeesharp.business.modules.mall.dto.MallCategorySpecSaveDTO;
import com.jeesharp.business.modules.mall.service.MallCategorySpecService;
import com.jeesharp.business.modules.mall.vo.MallSpecOptionVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 类目可用规格白名单应用服务：供管理端维护与发布模板页筛选规格。
 *
 * @author jeesharp
 * @since 2026-05-15
 */
@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class MallCategorySpecApplicationService {

    private final MallCategorySpecService mallCategorySpecService;

    public List<MallSpecOptionVO> listByCategoryId(String categoryId) {
        return mallCategorySpecService.listSpecOptionsByCategoryId(categoryId);
    }

    public List<MallSpecOptionVO> listByTemplateId(String templateId) {
        return mallCategorySpecService.listSpecOptionsByTemplateId(templateId);
    }

    @Transactional(readOnly = false)
    public void save(MallCategorySpecSaveDTO dto) {
        List<String> ids = dto.getSpecIds() != null ? dto.getSpecIds() : List.of();
        mallCategorySpecService.replaceSpecsForCategory(dto.getCategoryId(), ids);
    }
}
