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

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.setting.convert.MarketingPosterTemplateConvert;
import com.jeesharp.business.modules.setting.dto.MarketingPosterTemplateSaveDTO;
import com.jeesharp.business.modules.setting.entity.MarketingPosterTemplate;
import com.jeesharp.business.modules.setting.service.MarketingPosterTemplateService;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateListVO;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateQueryVO;
import com.jeesharp.business.modules.setting.vo.MarketingPosterTemplateVO;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class MarketingPosterTemplateApplicationService {

    private final MarketingPosterTemplateService marketingPosterTemplateService;

    public MarketingPosterTemplateVO get(String id) {
        return MarketingPosterTemplateConvert.INSTANCE.toInfoVO(marketingPosterTemplateService.get(id));
    }

    public PageRespVO<MarketingPosterTemplateListVO> findPage(Page<MarketingPosterTemplate> page, MarketingPosterTemplateQueryVO query) {
        Page<MarketingPosterTemplate> result = marketingPosterTemplateService.findPage(page, query);
        return MarketingPosterTemplateConvert.INSTANCE.toPageRespVO(result);
    }

    @Transactional(readOnly = false)
    public void save(MarketingPosterTemplateSaveDTO dto) {
        MarketingPosterTemplate entity = MarketingPosterTemplateConvert.INSTANCE.toEntity(dto);
        if (StrUtil.isBlank(dto.getId())) {
            marketingPosterTemplateService.createMarketingPosterTemplate(entity);
            return;
        }
        marketingPosterTemplateService.updateMarketingPosterTemplate(entity);
    }

    @Transactional(readOnly = false)
    public void delete(String ids) {
        marketingPosterTemplateService.batchDelete(StrUtil.splitTrim(ids, ','));
    }
}
