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

import {
  TableSearchQuery,
  CreateRegulationQuery,
  RegulationDetailResponse,
  NoticeDetailResponse,
  UpdateNoticeQuery,
  CreateNoticeQuery,
} from '@/views/traffic/regulation/types';

export const getRegulationList = (params: QueryPageRequest<TableSearchQuery>) => {
  return http.request<QueryPageResponse<RegulationDetailResponse>>({
    url: '/ruleNotice/queryRuleNoticeInfoPage',
    method: 'post',
    params,
  });
};

export const createRegulation = (data: CreateRegulationQuery) => {
  return http.request({
    url: '/ruleNotice/saveRuleNoticeInfo',
    method: 'post',
    data,
  });
};

export const updateRegulation = (data: CreateRegulationQuery) => {
  return http.request({
    url: '/ruleNotice/updateRuleNoticeInfo',
    method: 'post',
    data,
  });
};

export const getRegulationDetail = (id: number) => {
  return http.request<RegulationDetailResponse>({
    url: `/ruleNotice/queryRuleNoticeInfo?id=${id}`,
    method: 'post',
  });
};

// export const changeRegulationState = (data: { id: number; effectState: number }) => {
//   return http.request({
//     url: '/ruleNotice/updateRuleNoticeInfo',
//     method: 'post',
//     data,
//   });
// };

export const deleteRegulation = (id: number) => {
  return http.request({
    url: `/ruleNotice/deleteRuleNoticeInfo?id=${id}`,
    method: 'post',
  });
};

export const getNoticeList = (params: QueryPageRequest<TableSearchQuery>) => {
  return getRegulationList(params);
};

export const createNotice = (data: CreateNoticeQuery) => {
  return http.request({
    url: '/ruleNotice/saveRuleNoticeInfo',
    method: 'post',
    data,
  });
};

export const updateNotice = (data: UpdateNoticeQuery) => {
  return http.request({
    url: '/ruleNotice/updateRuleNoticeInfo',
    method: 'post',
    data,
  });
};

export const getNoticeDetail = (id: number) => {
  return http.request<NoticeDetailResponse>({
    url: `/ruleNotice/queryRuleNoticeInfo?id=${id}`,
    method: 'post',
  });
};

// export const changeNoticeState = (data: { id: number; effectState: number }) => {
//   return changeRegulationState(data);
// };

export const deleteNotice = (id: number) => {
  return deleteRegulation(id);
};
