package de.votian.services.controller;

import de.votian.services.entity.MetaType;
import de.votian.services.repository.MetaTypeRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/metatypes")
public class MetaTypeController {

    private final MetaTypeRepository metaTypeRepository;

    public MetaTypeController(MetaTypeRepository metaTypeRepository) {
        this.metaTypeRepository = metaTypeRepository;
    }

    @GetMapping("/type/{type}")
    public ResponseEntity<List<MetaType>> findByType(@PathVariable String type) {
        return ResponseEntity.ok(metaTypeRepository.findByTypeOrderBySort(type));
    }

    @GetMapping("/vehicletypes")
    public ResponseEntity<List<MetaType>> getVehicleTypes() {
        return ResponseEntity.ok(metaTypeRepository.findByTypeOrderBySort("vehicletype"));
    }

    @GetMapping("/permanent-types")
    public ResponseEntity<List<MetaType>> getPermanentTypes() {
        return ResponseEntity.ok(metaTypeRepository.findByTypeOrderBySort("permanent"));
    }
}
