package org.wfc.system.service.impl;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.wfc.common.core.utils.PageUtils;
import org.wfc.common.core.utils.ResponseUtils;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.omada.api.log.OmadaLogApi;
import org.wfc.omada.api.log.model.DeleteSiteAlertLogListOpenApiVo;
import org.wfc.omada.api.log.model.OperationResponseAlertLogGridVoAlertLogOpenApiVo;
import org.wfc.omada.api.log.model.OperationResponseWithoutResult;
import org.wfc.omada.api.log.model.ResolveSiteLogListOpenApiVo;
import org.wfc.system.service.ISysOmadaLogService;

import java.util.Objects;

/**
 * @description: omada log service impl
 * @author: cyc
 * @since: 2025-06-03
 */
@Service
public class SysOmadaLogServiceImpl implements ISysOmadaLogService {

    @Autowired
    private OmadaLogApi omadaLogApi;


    @Override
    public TableDataInfo getAlertLogsForSite(String siteId, Integer pageNum, Integer pageSize, Long filtersTimeStart, Long filtersTimeEnd, String filtersModule, Boolean filtersResolved) {
        if (StrUtil.isEmpty(filtersModule)) {
            filtersModule = null;
        }
        ResponseEntity<OperationResponseAlertLogGridVoAlertLogOpenApiVo> response = omadaLogApi.getAlertLogsForSite(siteId, pageNum, pageSize, filtersTimeStart, filtersTimeEnd, filtersModule, filtersResolved);
        ResponseUtils.checkResponse(Objects.requireNonNull(response.getBody()).getErrorCode(), response.getBody().getMsg());
        return PageUtils.getDataTable(response.getBody().getResult().getData(), response.getBody().getResult().getTotalRows());
    }

    @Override
    public boolean resolveAlertForSite(String siteId, ResolveSiteLogListOpenApiVo resolveSiteLogListOpenApiVo) {
        ResponseEntity<OperationResponseWithoutResult> response = omadaLogApi.resolveAlertForSite(siteId, resolveSiteLogListOpenApiVo);
        ResponseUtils.checkResponse(Objects.requireNonNull(response.getBody()).getErrorCode(), response.getBody().getMsg());
        return true;
    }

    @Override
    public boolean deleteAlertLogsForSite(String siteId, DeleteSiteAlertLogListOpenApiVo deleteSiteAlertLogListOpenApiVo) {
        ResponseEntity<OperationResponseWithoutResult> response = omadaLogApi.deleteAlertLogsForSite(siteId, deleteSiteAlertLogListOpenApiVo);
        ResponseUtils.checkResponse(Objects.requireNonNull(response.getBody()).getErrorCode(), response.getBody().getMsg());
        return true;
    }

}
