package ru.kayashov.bar.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.kayashov.bar.controller.dto.bar.BarResponseDto;
import ru.kayashov.bar.service.BarService;

import java.util.List;

@Slf4j
@CrossOrigin(origins = {"*"})
@RestController
@RequestMapping("/api/bar")
@RequiredArgsConstructor
public class BarController {

    private final BarService barService;

    @PostMapping("/change/{id}")
    public void changeActiveBar(@PathVariable Long id) {
        barService.changeActiveBar(id);
    }

    @DeleteMapping("/{id}")
    public void deleteBar(@PathVariable Long id) {
        barService.deleteBar(id);
    }

    @PostMapping("/{name}")
    public BarResponseDto createBar(@PathVariable String name) {
        return barService.createBar(name);
    }

    @GetMapping("/all")
    public List<BarResponseDto> getAll() {
        return barService.findAllBar();
    }
}
