package dev.dinauer.maven.maven.core;

import dev.dinauer.maven.jpa.maven.GroupId;
import dev.dinauer.maven.jpa.maven.repo.GroupRepo;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.time.ZonedDateTime;
import java.util.Optional;

@ApplicationScoped
public class GroupService
{
    @Inject
    GroupRepo groupRepo;

    public GroupId findOrCreate(String groupId)
    {
        Optional<GroupId> group = groupRepo.findOptionalByGroupId(groupId);
        if (group.isPresent())
        {
            return group.get();
        }
        else
        {
            return new GroupId().setGroupId(groupId).setCreatedAt(ZonedDateTime.now());
        }
    }
}
