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

import type {
  ActTableQuery,
  ActTableData,
  CreateActQuery,
  UpdateActQuery,
} from '@/views/traffic/violation/act/types.ts';

export function getActTableList(data: QueryPageRequest<ActTableQuery>) {
  return http.request<QueryPageResponse<ActTableData>>({
    url: '/trafficViolation/queryTrafficViolationPage',
    method: 'post',
    data,
  });
}

export function getActDataDetail(id: number) {
  return http.request<ActTableData>({
    url: `/trafficViolation/queryTrafficViolation?id=${id}`,
    method: 'post',
  });
}

export function noticeActData(violationIds: number[] | number) {
  return http.request({
    url: `/trafficViolation/updateTrafficViolationNotice?trafficViolationIds=${violationIds}`,
    method: 'post',
  });
}

export function deleteActData(violationIds: number[] | number) {
  return http.request({
    url: `/trafficViolation/deleteTrafficViolation?trafficViolationIds=${violationIds}`,
    method: 'post',
  });
}

export function updateActData(data: UpdateActQuery) {
  return http.request({
    url: '/trafficViolation/updateTrafficViolation',
    method: 'post',
    data,
  });
}

export function createActData(data: CreateActQuery) {
  return http.request({
    url: '/trafficViolation/saveTrafficViolation',
    method: 'post',
    data,
  });
}

export function exportActViolation(data: ActTableQuery) {
  return http.request(
    {
      url: '/trafficViolation/exportTrafficViolationList',
      method: 'post',
      data,
      responseType: 'blob',
    },
    {
      isTransformResponse: false,
    },
  );
}

export function updateRealtimeNotice(data: { realtimeNotice: boolean; speedLimit: number }) {
  return http.request({
    url: '/trafficViolation/updateRealtimeNoticeConfig',
    method: 'post',
    data,
  });
}

export function getRealtimeNoticeConfig() {
  return http.request<{ realtimeNotice: boolean; speedLimit: number | null }>({
    url: '/trafficViolation/queryRealtimeNoticeConfig',
    method: 'get',
  });
}
