package com.caliverse.admin.domain.api;

import com.caliverse.admin.domain.request.AdminRequest;
import com.caliverse.admin.domain.request.AuthenticateRequest;
import com.caliverse.admin.domain.response.AdminResponse;
import com.caliverse.admin.domain.response.GroupResponse;
import com.caliverse.admin.domain.service.AdminService;
import com.caliverse.admin.domain.service.GroupService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "운영자 조회", description = "운영자 조회 메뉴 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/admin")

public class AdminController {

    private final AdminService adminService;
    private final GroupService groupService;

    //사용자 정보 조회
    @GetMapping("/info")
    public ResponseEntity<AdminResponse> getAdminInfo(){
        return ResponseEntity.ok().body(adminService.getAdminInfo());
    }
    // 패스워드 초기화
    @PostMapping("/init-password")
    public ResponseEntity<AdminResponse> initPassword(@RequestBody AuthenticateRequest authenticateRequest){
        return ResponseEntity.ok().body(adminService.initPassword(authenticateRequest));
    }
    // 패스워드 변경
    @PatchMapping("/change-password")
    public ResponseEntity<AdminResponse> updatePassword(@RequestBody AuthenticateRequest authenticateRequest){
        return ResponseEntity.ok().body(adminService.updatePassword(authenticateRequest));
    }

    // 관리자 권한 리스트 조회
    @GetMapping("/group-list")
    public ResponseEntity<GroupResponse> getAllGroupList(){
        return ResponseEntity.ok().body(groupService.getAllGroups());
    }
    // 운영자 리스트 조회
    @GetMapping("/list")
    public ResponseEntity<AdminResponse> getAdminList(
            @RequestParam Map<String, String> requestParams){
        return ResponseEntity.ok().body(adminService.getAdminList(requestParams));
    }

    // 로그인 승인/불가
    @PatchMapping
    public ResponseEntity<AdminResponse> updateStatus(
            @RequestBody AdminRequest adminRequest) {
        return ResponseEntity.ok().body(adminService.updateStatus(adminRequest));
    }
    //운영자 그룹 저장
    @PutMapping
    public ResponseEntity<AdminResponse> updateGroup(
            @RequestBody AdminRequest adminRequest) {
        return ResponseEntity.ok().body(adminService.updateGroup(adminRequest));
    }

    // 운영자 선택 삭제
    @DeleteMapping
    public ResponseEntity<AdminResponse> delete(
            @RequestBody AdminRequest adminRequest) {
        return ResponseEntity.ok().body(adminService.deleteAdmin(adminRequest));
    }

}
