/**
 * 应用路径解析器。
 *
 * <p>用于将配置中的相对路径解析为基于应用工作目录的绝对路径。</p>
 */
package com.hertz.config;

import java.io.File;
import org.springframework.stereotype.Service;

@Service
public class AppPathResolver {

  private final File baseDir;

  public AppPathResolver() {
    String userDir = System.getProperty("user.dir");
    this.baseDir = userDir == null || userDir.isBlank() ? new File(".") : new File(userDir);
  }

  public String resolve(String path) {
    if (path == null || path.isBlank()) {
      return path;
    }
    File file = new File(path);
    if (file.isAbsolute()) {
      return file.getAbsolutePath();
    }
    return new File(baseDir, path).getAbsolutePath();
  }
}
