package com.example.dateplanner.services;

import com.example.dateplanner.models.entities.Organization;
import com.example.dateplanner.repositories.OrganizationRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.UUID;

@Service
@AllArgsConstructor
public class OrganizationService {
    private final OrganizationRepository organizationRepository;

    public Flux<Organization> getByOwner(UUID ownerUuid) {
        return organizationRepository.findAllByOwnerUuid(ownerUuid);
    }

    public Mono<Organization> create(Organization organization) {
        organization.setCreatedAt(LocalDateTime.now());
        organization.setUpdatedAt(LocalDateTime.now());
        return organizationRepository.save(organization);
    }
}
