package com.writeoff.module.system.controller;

import com.writeoff.common.api.ApiResponse;
import com.writeoff.module.system.dto.DisableDelegationRequest;
import com.writeoff.module.system.service.UserDelegationService;
import com.writeoff.security.DataScopeType;
import com.writeoff.security.RequirePermission;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/delegations")
public class UserDelegationController {
    private final UserDelegationService userDelegationService;

    public UserDelegationController(UserDelegationService userDelegationService) {
        this.userDelegationService = userDelegationService;
    }

    @PostMapping("/{id}/disable")
    @RequirePermission(value = "user.delegation.manage", dataScope = DataScopeType.TENANT, auditAction = "USER_DELEGATION_DISABLE")
    public ApiResponse<String> disable(@PathVariable("id") Long id, @RequestBody @Valid DisableDelegationRequest request) {
        userDelegationService.disable(id, request);
        return ApiResponse.success("OK");
    }
}
