package com.malk.benteler.controller;

import com.malk.benteler.dto.EiamFormSyncResult;
import com.malk.benteler.dto.FormInstanceRequest;
import com.malk.benteler.service.BentelerYidaSyncService;
import com.malk.server.common.McR;
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;

/**
 * 本特勒宜搭调用 EIAM 批量用户接口。
 */
@RestController
@RequestMapping("/benteler/eiam/users")
public class EiamController {

    private final BentelerYidaSyncService yidaSyncService;

    public EiamController(BentelerYidaSyncService yidaSyncService) {
        this.yidaSyncService = yidaSyncService;
    }

    /**
     * 批量创建 EIAM 用户。
     *
     * @param request 批量创建请求
     * @return 宜搭可逐条回写的执行结果
     */
    @PostMapping("/batch-create")
    public McR<EiamFormSyncResult> batchCreate(@RequestBody FormInstanceRequest request) {
        return McR.success(yidaSyncService.syncCreate(
                request == null ? null : request.getFormInstanceId()));
    }

    /**
     * 批量更新 EIAM 用户。
     *
     * @param request 批量更新请求
     * @return 宜搭可逐条回写的执行结果
     */
    @PostMapping("/batch-update")
    public McR<EiamFormSyncResult> batchUpdate(@RequestBody FormInstanceRequest request) {
        return McR.success(yidaSyncService.syncUpdate(
                request == null ? null : request.getFormInstanceId()));
    }

    /**
     * 批量删除 EIAM 用户。
     *
     * @param request 批量删除请求
     * @return 宜搭可逐条回写的执行结果
     */
    @PostMapping("/batch-delete")
    public McR<EiamFormSyncResult> batchDelete(@RequestBody FormInstanceRequest request) {
        return McR.success(yidaSyncService.syncDelete(
                request == null ? null : request.getFormInstanceId()));
    }
}
