import { http } from '@/utils/http/axios';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';

import type {
  AccessTableQuery,
  AccessDetailResponse,
  CreateAccessQuery,
  UpdateAccessQuery,
} from '@/views/security-confidentiality/access-control/types';

export function getAccessRecordList(data: QueryPageRequest<AccessTableQuery>) {
  return http.request<QueryPageResponse<AccessDetailResponse>>({
    url: '/accessControlAbnormalRecord/queryAccessControlAbnormalRecordPage',
    method: 'POST',
    data,
  });
}

export function exportAccessRecordList(data: AccessTableQuery) {
  return http.request(
    {
      url: '/accessControlAbnormalRecord/exportAccessControlAbnormalRecord',
      method: 'post',
      data,
      responseType: 'blob',
    },
    {
      isTransformResponse: false,
    },
  );
}

export function deleteAccessRecord(id: number) {
  return http.request({
    url: `/accessControlAbnormalRecord/deleteAccessControlAbnormalRecord?recordId=${id}`,
    method: 'DELETE',
  });
}

export function createAccessRecord(data: CreateAccessQuery) {
  return http.request({
    url: '/accessControlAbnormalRecord/saveAccessControlAbnormalRecord',
    method: 'POST',
    data,
  });
}

export function getAccessRecordDetail(id: number) {
  return http.request<AccessDetailResponse>({
    url: `/accessControlAbnormalRecord/queryAccessControlAbnormalRecordById?recordId=${id}`,
    method: 'GET',
  });
}

export function updateAccessRecord(data: UpdateAccessQuery) {
  return http.request({
    url: '/accessControlAbnormalRecord/updateAccessControlAbnormalRecord',
    method: 'PUT',
    data,
  });
}
