package org.wfc.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.wfc.common.core.utils.ResponseUtils;
import org.wfc.omada.api.accesscontrol.OmadaAccessControlApi;
import org.wfc.omada.api.accesscontrol.model.OperationResponsePortalAccessControlOpenApiVo;
import org.wfc.omada.api.accesscontrol.model.PortalAccessControlOpenApiVo;
import org.wfc.system.service.ISysAccessControlService;

import java.util.Objects;

/**
 * @description: access control service impl
 * @author: cyc
 * @since: 2025-06-04
 */
@Service
public class SysAccessControlServiceImpl implements ISysAccessControlService {

    @Autowired
    private OmadaAccessControlApi omadaAccessControlApi;

    public PortalAccessControlOpenApiVo getAccessControl(String siteId) {
        ResponseEntity<OperationResponsePortalAccessControlOpenApiVo> response = omadaAccessControlApi.getAccessControl(siteId);
        ResponseUtils.checkResponse(Objects.requireNonNull(response.getBody()).getErrorCode(), response.getBody().getMsg());
        return response.getBody().getResult();
    }

    public boolean modifyAccessControl(String siteId, PortalAccessControlOpenApiVo portalAccessControlOpenApiVo) {
        ResponseEntity<OperationResponsePortalAccessControlOpenApiVo> response = omadaAccessControlApi.modifyAccessControl(siteId, portalAccessControlOpenApiVo);
        ResponseUtils.checkResponse(Objects.requireNonNull(response.getBody()).getErrorCode(), response.getBody().getMsg());
        return true;
    }

}
