package com.zioinfo.signage.uiws.system.controller;

import com.zioinfo.signage.common.ApiResponse;
import com.zioinfo.signage.uiws.system.dto.IdsRequest;
import com.zioinfo.signage.uiws.system.dto.PageResponse;
import com.zioinfo.signage.uiws.system.dto.RoleDto;
import com.zioinfo.signage.uiws.system.dto.RoleSaveDto;
import com.zioinfo.signage.uiws.system.service.RoleService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/** 2.1 권한(roles) — 목록/등록/상세/수정/다중삭제. base: /api/system/roles */
@RestController
@RequestMapping("/api/system/roles")
@RequiredArgsConstructor
public class RoleController {

    private final RoleService roleService;

    @GetMapping
    public ApiResponse<PageResponse<RoleDto>> list(
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "20") int size) {
        return ApiResponse.ok(roleService.list(keyword, page, size));
    }

    @PostMapping
    public ApiResponse<RoleDto> create(@Valid @RequestBody RoleSaveDto dto) {
        return ApiResponse.ok(roleService.create(dto));
    }

    @GetMapping("/{id}")
    public ApiResponse<RoleDto> get(@PathVariable("id") String id) {
        return ApiResponse.ok(roleService.get(id));
    }

    @PutMapping("/{id}")
    public ApiResponse<RoleDto> update(@PathVariable("id") String id, @Valid @RequestBody RoleSaveDto dto) {
        return ApiResponse.ok(roleService.update(id, dto));
    }

    @DeleteMapping
    public ApiResponse<Void> delete(@Valid @RequestBody IdsRequest req) {
        roleService.delete(req.ids());
        return ApiResponse.ok(null);
    }
}
