import { create } from 'zustand';

interface ObjectsState {
    selectedRegion: number | null;
    selectedDistrict: number | null;
    selectedCity: number | null;
    selectedYear: number | null;
    currentObjectId: string | null;
}

export const useObjectsStore = create<ObjectsState>(() => ({
    selectedRegion: null,
    selectedDistrict: null,
    selectedCity: null,
    selectedYear: null,
    currentObjectId: null
}));

const getSelectedCity = () => {
    return useObjectsStore.getState().selectedCity
}

const setSelectedRegion = (region: number | null) => {
    useObjectsStore.setState(() => ({ selectedRegion: region }))
}

const setSelectedDistrict = (district: number | null) => {
    useObjectsStore.setState(() => ({ selectedDistrict: district }))
}

const setSelectedCity = (city: number | null) => {
    useObjectsStore.setState(() => ({ selectedCity: city }))
}

const getSelectedYear = () => {
    return useObjectsStore.getState().selectedYear
}

const setSelectedYear = (year: number | null) => {
    useObjectsStore.setState(() => ({ selectedYear: year }))
}

const getCurrentObjectId = () => {
    return useObjectsStore.getState().currentObjectId
}

const setCurrentObjectId = (objectId: string | null) => {
    useObjectsStore.setState(() => ({ currentObjectId: objectId }))
}

export {
    getSelectedCity,
    setSelectedCity,
    getSelectedYear,
    setSelectedYear,
    getCurrentObjectId,
    setCurrentObjectId,
    setSelectedRegion,
    setSelectedDistrict
}