package com.bio.bio_backend.domain.base.authgroupresource.controller;

import com.bio.bio_backend.domain.base.authgroupresource.dto.AuthGroupResourceDto;
import com.bio.bio_backend.domain.base.authgroupresource.dto.ReplaceAuthGroupResourcesRequest;
import com.bio.bio_backend.domain.base.authgroupresource.service.AuthGroupResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

@RestController
@RequestMapping("/auth_group_resource")
@RequiredArgsConstructor
@Tag(name = "AuthGroupResource", description = "")
@Slf4j
public class AuthGroupResourceController {

    private final AuthGroupResourceService service;

    @PostMapping("/create")
    public AuthGroupResourceDto create(@RequestBody AuthGroupResourceDto dto) {
        return service.create(dto);
    }

    @GetMapping("/{id}")
    public AuthGroupResourceDto getById(@PathVariable Long id) {
        return service.getById(id);
    }

    @GetMapping
    public List<AuthGroupResourceDto> getAll() {
        return service.getAll();
    }

    @PutMapping("/{id}")
    public AuthGroupResourceDto update(@PathVariable Long id, @RequestBody AuthGroupResourceDto dto) {
        return service.update(id, dto);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        service.delete(id);
    }

    @PostMapping("/replace")
    public void replaceAuthGroupResources(@RequestBody ReplaceAuthGroupResourcesRequest request) {
        service.replaceAuthGroupResources(request.getAuthGroupOid(), request.getResourceOids());
    }
}
