import { create } from "zustand";

import { ReportType } from "@/contracts/client.schemas";

interface State {
	assetIdList: string[];
	type: ReportType;
	extraByType: Record<ReportType, unknown>;

	setAssetIdList: (assetIdList: string[]) => void;
	setType: (type: ReportType) => void;
	setExtraForType: (type: ReportType, extra: unknown) => void;
	getExtraForType: (type: ReportType) => unknown;
}

export const useReportBuilderStore = create<State>((set, get) => ({
	assetIdList: [],
	type: ReportType.ByState,
	extraByType: {
		[ReportType.ByState]: { Properties: ["Name", "Description"] },
		[ReportType.Journal]: {
			OnlyUserLogs: false,
			OnlyFire: false,
			From: new Date(),
			To: new Date(),
		},
		[ReportType.SummaryEvents]: { From: new Date(), To: new Date() },
	},

	setAssetIdList: (assetIdList: string[]) => {
		set({ assetIdList });
	},
	setType: (type: ReportType) => {
		set({ type });
	},
	setExtraForType: (type: ReportType, extra: unknown) => {
		set((state) => ({
			extraByType: {
				...state.extraByType,
				[type]: extra,
			},
		}));
	},
	getExtraForType: (type: ReportType) => {
		return get().extraByType[type];
	},
}));
