package com.jwipc.sys.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.sys.dto.*;
import com.jwipc.sys.logic.RoleLogic;
import com.jwipc.sys.model.query.RoleListQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/role")
@RequiredArgsConstructor
@Slf4j
public class RoleRestController {
    private final RoleLogic roleLogic;

    @GetMapping("list")
    public PageView list(RoleListQuery query) {
        return roleLogic.getList(query);
    }

    @PostMapping("save")
    public ResponseEntity save(RoleAddDTO roleAddDTO) {
        roleLogic.save(roleAddDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("update")
    public ResponseEntity update(RoleEditDTO roleEditDTO) {
        roleLogic.update(roleEditDTO);
        return ResponseEntity.ok().build();
    }

    @GetMapping("permissionGrid")
    public ResponseEntity permissionGrid(int type) {
        List<RolePermTreeDTO> list = roleLogic.getPermissionGrid(type);
        return ResponseEntity.ok(list);
    }

    @PostMapping("updatePermission")
    public ResponseEntity updatePermission(@RequestBody UpdatePermissionDTO updatePermissionDTO) {
        roleLogic.updatePermission(updatePermissionDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateDealtConfig")
    public ResponseEntity updateDealtConfig(@RequestBody DealtWithTargetRoleUpdateDTO updatePermissionDTO) {
        roleLogic.updateDealtConfig(updatePermissionDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("remove")
    public ResponseEntity remove(Long id) {
        roleLogic.remove(id);
        return ResponseEntity.ok().build();
    }


}
