//上报事件
import { create } from "zustand";

//上报事件参数
let eventReportForm: API.ReportEventSourceInfoReq = {
  standardEventContent: "",
  collectionMode: "",
  handlingMethod: "1",
  eventReportInfoExtend: {
    sourceSystemCode: "XD-CITIZEN", //固定传
    sourceSystem: "市民之声", //固定传巡查通
    articleCode: "",
    newInstCondName: "", //名称
    newInstCondCode: "", //立案条件
    cityCode: "",
    cityName: "",
    districtCode: "",
    districtName: "",
    streetCode: "",
    streetName: "",
    communityCode: "",
    communityName: "",
    lon: "", //事件经度
    lat: "", //事件纬度
    coordinateType: "", //坐标类型
    address: "",
    aiFlag: "0", //是否ai识别分类0
    roadName: "",
    eventIndustryCode: "",
    eventIndustryName: "",
  },
  beforeFilePath: [], //图片
};

export type DiscoverEntryDto =
  | "take" //拍照发现 极简上报
  | "liftFinger"; //举手之劳

const useReportStore = create<{
  standardEventContent: string;
  discoverEntry: DiscoverEntryDto;
  eventReportInfoExtend: API.ReportEventSourceInfoReq["eventReportInfoExtend"];
  updateReportEvent: (obj?: any) => void;
  updateContent: (text?: any) => void;
  updateDiscover: (type: DiscoverEntryDto) => void;
  clearStore: () => void;
}>((set) => ({
  standardEventContent: "",
  eventReportInfoExtend: eventReportForm.eventReportInfoExtend,
  discoverEntry: "take",
  //修改上报事件参数
  updateReportEvent: (obj?: any) =>
    set((state) => ({
      eventReportInfoExtend: Object.assign(state.eventReportInfoExtend, obj),
    })),
  //修改描述
  updateContent(text) {
    set({
      standardEventContent: text,
    });
  },

  //修改入口，判断识别弹出框显示
  updateDiscover(type: DiscoverEntryDto) {
    set({
      discoverEntry: type,
    });
  },

  //重置store
  clearStore() {
    set({
      eventReportInfoExtend: eventReportForm.eventReportInfoExtend,
      standardEventContent: "",
    });
  },
}));

export default useReportStore;
