using Backend.Models;

namespace Backend.Repositories;

public class IssueRepository : IIssueRepository
{
    private static Issue[] issues = {
        new Issue(){
            IssueId = 1,
            Title = "Handle Issues with API",
            Project = "PRJ",
            Text = "<p>API should handle issues.</p>"
        },
        new Issue(){
            IssueId = 2,
            Title = "Handle Issues with API GET",
            Project = "PRJ",
            Text = "<p>GET should handle issues.</p>",
            ParentId = 1
        },
        new Issue(){
            IssueId = 3,
            Title = "Handle Issues with API POST",
            Project = "PRJ",
            Text = "<p>POST should handle issues.</p>",
            ParentId = 1
        },
        new Issue(){
            IssueId = 4,
            Title = "This is a Test Issue",
            Project = "TEST",
            Text = "<p>This is a Test Issue</p>",
            ParentId = 1
        },
    };

    public IssueRepository()
    {

    }

    public Issue[] GetIssues()
    {
        return issues;
    }

    public Issue? GetIssueById(int Id)
    {
        Issue issue = issues.Where(p => p.IssueId == Id).First();
        return issue;
    }

    public Issue[]? GetIssuesByProject(string Project)
    {
        Issue[] FoundIssues = issues.Where(p => p.Project.ToLower() == Project.ToLower()).ToArray();
        return FoundIssues;
    }
}