package com.example.Portfolio.Services;

import java.util.List;
import org.springframework.stereotype.Service;
import com.example.Portfolio.Component.MarkdownService;
import com.example.Portfolio.DTO.ProjectView;

@Service
public class ProjectService {

    private final GiteaRepoService giteaService;
    private final MarkdownService markdownService;

    public ProjectService(GiteaRepoService giteaService,
            MarkdownService markdownService) {
        this.giteaService = giteaService;
        this.markdownService = markdownService;
    }

    public ProjectView getProject(String repo) {

        var repoMeta = giteaService.getRepository("kiyan", repo);

        String overview = markdownService.toHtml(
                giteaService.getRawFile("kiyan", repo, "main", "README.md"));

        String docs = markdownService.toHtml(
                giteaService.getRawFile("kiyan", repo, "main", "documentation.md"));

        String future = markdownService.toHtml(
                giteaService.getRawFile("kiyan", repo, "main", "future.md"));

        String stack = markdownService.toHtml(
                giteaService.getRawFile("kiyan", repo, "main", "stack.md"));

        List<String> screenshots = giteaService.getScreenshots("kiyan", repo);

        return new ProjectView(
                repoMeta.name(),
                repoMeta.description(),
                repoMeta.html_url(),
                repoMeta.website(),
                overview,
                docs,
                future,
                stack,
                screenshots);
    }
}
