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

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.food.convert.FoodMealServiceAreaConvert;
import com.jeesharp.business.modules.food.dto.FoodMealServiceAreaSaveDTO;
import com.jeesharp.business.modules.food.entity.FoodMealServiceArea;
import com.jeesharp.business.modules.food.service.FoodMealServiceAreaService;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaInfoVO;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaListVO;
import com.jeesharp.business.modules.food.vo.FoodMealServiceAreaQueryVO;
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 FoodMealServiceAreaApplicationService {

    private final FoodMealServiceAreaService foodMealServiceAreaService;

    public FoodMealServiceAreaInfoVO get(String id) {
        return FoodMealServiceAreaConvert.INSTANCE.toInfoVO(foodMealServiceAreaService.get(id));
    }

    public PageRespVO<FoodMealServiceAreaListVO> findPage(Page<FoodMealServiceArea> page, FoodMealServiceAreaQueryVO query) {
        return FoodMealServiceAreaConvert.INSTANCE.toPageRespVO(foodMealServiceAreaService.findPage(page, query));
    }

    @Transactional(readOnly = false)
    public void save(FoodMealServiceAreaSaveDTO dto) {
        FoodMealServiceArea entity = FoodMealServiceAreaConvert.INSTANCE.toEntity(dto);
        if (StrUtil.isBlank(dto.getId())) {
            foodMealServiceAreaService.createArea(entity);
            return;
        }
        foodMealServiceAreaService.updateArea(entity);
    }

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