package com.escolapios.fctmongo.controller;

import com.escolapios.fctmongo.entity.TutorEmpresa;
import com.escolapios.fctmongo.service.TutorEmpresaService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/tutores")
public class TutorEmpresaController {

    private final TutorEmpresaService service;

    public TutorEmpresaController(TutorEmpresaService service) {
        this.service = service;
    }

    @GetMapping
    public ResponseEntity<List<TutorEmpresa>> listar() {
        return ResponseEntity.ok(service.obtenerTodos());
    }

    @GetMapping("/{id}")
    public ResponseEntity<TutorEmpresa> obtenerPorId(@PathVariable String id) {
        return ResponseEntity.ok(service.obtenerPorId(id));
    }

    @GetMapping("/empresa/{empresaId}")
    public ResponseEntity<List<TutorEmpresa>> listarPorEmpresa(@PathVariable String empresaId) {
        return ResponseEntity.ok(service.obtenerPorEmpresa(empresaId));
    }

    @PostMapping
    public ResponseEntity<TutorEmpresa> crear(@RequestBody TutorEmpresa tutor) {
        return new ResponseEntity<>(service.guardar(tutor), HttpStatus.CREATED);
    }

    @PutMapping("/{id}")
    public ResponseEntity<TutorEmpresa> actualizar(@PathVariable String id, @RequestBody TutorEmpresa tutor) {
        tutor.setId(id);
        return ResponseEntity.ok(service.guardar(tutor));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> eliminar(@PathVariable String id) {
        service.eliminar(id);
        return ResponseEntity.noContent().build();
    }
}
