package research.loghunter.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import research.loghunter.dto.ServerLogPathDto;
import research.loghunter.service.ServerLogPathService;

import java.util.List;

@RestController
@RequestMapping("/api/log-paths")
@RequiredArgsConstructor
public class ServerLogPathController {

    private final ServerLogPathService logPathService;

    @GetMapping("/server/{serverId}")
    public ResponseEntity<List<ServerLogPathDto>> findByServerId(@PathVariable Long serverId) {
        return ResponseEntity.ok(logPathService.findByServerId(serverId));
    }

    @GetMapping("/server/{serverId}/active")
    public ResponseEntity<List<ServerLogPathDto>> findActiveByServerId(@PathVariable Long serverId) {
        return ResponseEntity.ok(logPathService.findActiveByServerId(serverId));
    }

    @GetMapping("/{id}")
    public ResponseEntity<ServerLogPathDto> findById(@PathVariable Long id) {
        return ResponseEntity.ok(logPathService.findById(id));
    }

    @PostMapping
    public ResponseEntity<ServerLogPathDto> create(@RequestBody ServerLogPathDto dto) {
        return ResponseEntity.ok(logPathService.create(dto));
    }

    @PutMapping("/{id}")
    public ResponseEntity<ServerLogPathDto> update(@PathVariable Long id, @RequestBody ServerLogPathDto dto) {
        return ResponseEntity.ok(logPathService.update(id, dto));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        logPathService.delete(id);
        return ResponseEntity.ok().build();
    }
}
