package com.lingyue.graph.service;

import com.lingyue.graph.entity.Graph;
import com.lingyue.graph.repository.GraphRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 关系网络服务（基础框架）
 */
@Service
@RequiredArgsConstructor
public class GraphService {
    
    private final GraphRepository graphRepository;
    
    /**
     * 根据ID获取关系网络
     */
    public Graph getGraphById(String graphId) {
        return graphRepository.selectById(graphId);
    }
    
    /**
     * 保存关系网络
     */
    public Graph saveGraph(Graph graph) {
        if (graph.getId() == null) {
            graph.setId(java.util.UUID.randomUUID().toString().replace("-", ""));
            graph.setCreateTime(new java.util.Date());
            graphRepository.insert(graph);
        } else {
            graph.setUpdateTime(new java.util.Date());
            graphRepository.updateById(graph);
        }
        return graph;
    }
    
    /**
     * 删除关系网络
     */
    public void deleteGraph(String graphId) {
        graphRepository.deleteById(graphId);
    }
    
    // TODO: 实现关系网络计算逻辑
}
