package com.malk.benteler.controller;

import com.malk.benteler.dto.EiamOrganizationalUnitOption;
import com.malk.benteler.service.EiamOrganizationalUnitLocalService;
import com.malk.server.common.McR;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 本特勒 EIAM 部门选择接口。
 */
@RestController
@RequestMapping("/benteler/eiam/organizational-units")
public class EiamOrganizationalUnitController {

    private final EiamOrganizationalUnitLocalService organizationalUnitService;

    public EiamOrganizationalUnitController(
            EiamOrganizationalUnitLocalService organizationalUnitService) {
        this.organizationalUnitService = organizationalUnitService;
    }

    /**
     * 按部门名称查询 EIAM 部门选项。
     *
     * @param name 部门名称关键字
     * @return 部门 ID 与“当前部门 (父部门)”显示名称
     */
    @GetMapping
    public McR<List<EiamOrganizationalUnitOption>> search(@RequestParam String name) {
        return McR.success(organizationalUnitService.searchByName(name));
    }
}
