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

import com.bio.bio_backend.domain.base.memberauthgroup.dto.MemberAuthGroupDto;
import com.bio.bio_backend.domain.base.memberauthgroup.dto.ReplaceMemberAuthGroupsRequest;
import com.bio.bio_backend.domain.base.memberauthgroup.service.MemberAuthGroupService;
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("/member_auth_group")
@RequiredArgsConstructor
@Tag(name = "MemberAuthGroup", description = "")
@Slf4j
public class MemberAuthGroupController {

    private final MemberAuthGroupService service;

    @PostMapping
    public MemberAuthGroupDto create(@RequestBody MemberAuthGroupDto dto) {
        return service.create(dto);
    }

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

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

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

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

    @PostMapping("/replace")
    public void replaceMemberAuthGroups(@RequestBody ReplaceMemberAuthGroupsRequest request) {
        service.replaceMemberAuthGroups(request.getMemberOid(), request.getAuthGroupOids());
    }
}
