package com.jeeplus.sys.feign;

import com.jeeplus.sys.domain.Role;
import com.jeeplus.sys.service.RoleService;
import com.jeeplus.sys.service.dto.RoleDTO;
import com.jeeplus.sys.service.mapstruct.RoleWrapper;
import com.jeeplus.sys.utils.TenantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class RoleApiImpl implements IRoleApi {

    @Autowired
    RoleService roleService;


    @Override
    public RoleDTO getRoleDTOByName(String name) {
        return RoleWrapper.INSTANCE.toDTO ( roleService.lambdaQuery ( ).eq ( Role::getTenantId, TenantUtils.getTenantId ( ) ).eq ( Role::getName, name ).one ( ) );
    }

    @Override
    public List<RoleDTO> getRoleDTOByNameAndTenantId(@RequestBody Map<String, String> keyMap) {
        return roleService.getRoleDTOByNameAndTenantId(keyMap);
    }

    @Override
    public RoleDTO getRoleDTOByName2(String name) {
        return roleService.getRoleByName2(name);
    }

    @Override
    public RoleDTO getRoleDTOById(String id) {
        return RoleWrapper.INSTANCE.toDTO ( roleService.lambdaQuery ( ).eq ( Role::getTenantId, TenantUtils.getTenantId ( ) ).eq ( Role::getId, id ).one ( ) );
    }

    @Override
    public RoleDTO getRoleDTOByIdForApp(String id) {
        return RoleWrapper.INSTANCE.toDTO ( roleService.lambdaQuery ( ).eq ( Role::getId, id ).one ( ) );

    }
}
