/**
 * @description: 交通事故记录管理
 */
import { http } from '@/utils/http/axios';
import type { QueryPageRequest, QueryPageResponse } from '@/types/basic-query';

/**
 * @description: 分页查询交通事故记录列表
 */
export interface AccidentListQuery {
  fieldType?: string;
  fieldContent?: string;
  startTime?: string;
  endTime?: string;
}
export interface AccidentInfoStruct {
  id?: number; // 自增主键
  accidentLocation?: string; // 事故地点
  accidentTime?: string; // 事故时间
  accidentDescription?: string; // 事故描述
  accidentImages?: string; // 事故图片
  remark?: string; // 备注
  createdById?: number; // 创建人id
  createdByName?: string; // 创建人姓名
  createdAt?: string; // 创建时间
  updatedAt?: string; // 更新时间
  isDeleted?: number; // 0-未删除，大于0(时间戳)-已删除
}
export const getAccidentInfoList = (params: QueryPageRequest<AccidentListQuery>) => {
  return http.request<QueryPageResponse<AccidentInfoStruct>>({
    url: '/trafficAccident/queryTrafficAccidentRecordPage',
    method: 'post',
    params,
  });
};

/**
 * @description: 添加交通事故记录
 */
export interface AccidentPersonnelInfoStruct {
  id?: number; // 自增主键
  accidentRecordId?: number; // 事故记录id
  carNum?: string; // 车牌号
  accidentPersonnel?: string; // 事故人员
  phoneNum?: string; // 联系方式
  createdAt?: string; // 创建时间
  updatedAt?: string; // 更新时间
  isDeleted?: number; // 0-未删除，大于0(时间戳)-已删除
}
export interface AddAccidentInfoStruct {
  trafficAccidentRecord: AccidentInfoStruct;
  accidentPersonnelInfoList: AccidentPersonnelInfoStruct[];
}
export const addVehicleInfo = (params: AddAccidentInfoStruct) => {
  return http.request({
    url: '/trafficAccident/saveTrafficAccidentRecord',
    method: 'post',
    params,
  });
};

/**
 * @description: 更新交通事故记录
 */
export const updateVehicleInfo = (params: AddAccidentInfoStruct) => {
  return http.request({
    url: '/trafficAccident/updateTrafficAccidentRecord',
    method: 'put',
    params,
  });
};

/**
 * @description: 删除交通事故记录（单个/批量）
 */
export const deleteAccidentInfo = (params: { accidentRecordIds: number[] }) => {
  return http.request({
    url: '/trafficAccident/deleteTrafficAccidentRecord',
    method: 'delete',
    params,
  });
};

/**
 * @description: 查询交通事故记录详情
 */
export const getAccidentInfoDetail = (params: { accidentRecordId: number }) => {
  return http.request({
    url: `/trafficAccident/queryTrafficAccidentRecordDetail?accidentRecordId=${params.accidentRecordId}`,
    method: 'get',
  });
};

/**
 * @description: 导出交通事故记录
 */
export function exportAccidentInfo(params: AccidentListQuery) {
  return http.request(
    {
      url: '/trafficAccident/exportTrafficAccidentRecord',
      method: 'post',
      responseType: 'blob',
      params,
    },
    { isTransformResponse: false },
  );
}
