package org.raddatz.familienarchiv.timeline;

import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.raddatz.familienarchiv.security.Permission;
import org.raddatz.familienarchiv.security.RequirePermission;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/api/timeline")
@Validated
@RequiredArgsConstructor
public class TimelineController {

    private final TimelineService timelineService;

    @GetMapping
    @RequirePermission(Permission.READ_ALL)
    public TimelineDTO getTimeline(
            @RequestParam(required = false) UUID personId,
            @RequestParam(required = false) @Min(0) Integer generation,
            @RequestParam(required = false) EventType type,
            @RequestParam(required = false) Integer fromYear,
            @RequestParam(required = false) Integer toYear) {
        return timelineService.assemble(new TimelineFilter(personId, generation, type, fromYear, toYear));
    }
}
