package com.persagy.adm.diagram.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.persagy.adm.diagram.dao.IconMapper;
import com.persagy.adm.diagram.entity.IconEntity;
import com.persagy.adm.diagram.service.IconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IconServiceImpl implements IconService {

    @Autowired
    private IconMapper iconMapper;

    /**
     * 保存图标
     *
     * @param entity 图标对象信息
     * @return
     */
    @Override
    public IconEntity saveIcon(IconEntity entity) {
        if (StrUtil.isNotBlank(entity.getId())) {
            IconEntity icon = iconMapper.selectById(entity.getId());
            if (null != icon) {
                iconMapper.updateById(entity);
                return entity;
            }
        }
        entity.setId(IdUtil.simpleUUID());
        iconMapper.insert(entity);
        return entity;
    }

    @Override
    public IconEntity getIconInfo(String iconId) {
        return iconMapper.selectById(iconId);
    }

    @Override
    public IconEntity getIconsByLegendId(String legendId, String skin) {
        return iconMapper.getIconsByLegendId(legendId, skin);
    }

    @Override
    public List<IconEntity> getIcons() {
        return iconMapper.getIcons();
    }

    /**
     * 根据系统类型获取所有图标
     *
     * @param systemType 系统类型
     * @return
     */
    @Override
    public List<IconEntity> getIconsBySystemType(String systemType) {
        return iconMapper.getIconsBySystemType(systemType);
    }
}
