package de.avatic.lcc.controller.configuration;

import com.azure.core.annotation.BodyParam;
import de.avatic.lcc.dto.configuration.apps.AppDTO;
import de.avatic.lcc.service.apps.AppsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/apps")
public class AppsController {


    private final AppsService appsService;

    public AppsController(AppsService appsService) {

        this.appsService = appsService;
    }

    @GetMapping({"", "/"})
    public ResponseEntity<List<AppDTO>> listApps() {
        return ResponseEntity.ok(appsService.listApps());
    }

    @PostMapping({"", "/"})
    public ResponseEntity<AppDTO> updateApp(@RequestBody AppDTO dto) {
        return ResponseEntity.ok(appsService.updateApp(dto));
    }

    @DeleteMapping({"/{id}", "/{id}/"})
    public ResponseEntity<Void> deleteApp(@PathVariable Integer id) {
        appsService.deleteApp(id);
        return ResponseEntity.ok().build();
    }


}
