import { create } from 'zustand';

export type DeviceLimitDevice = {
  id: string;
  deviceId: string;
  platform: string;
  model: string | null;
  name: string | null;
  osVersion: string | null;
  lastSeenAt: string;
  createdAt: string;
  isCurrent?: boolean;
};

type DeviceLimitState = {
  visible: boolean;
  devices: DeviceLimitDevice[];
  max: number;
  plan: string;
  show: (devices: DeviceLimitDevice[], max: number, plan: string) => void;
  hide: () => void;
  removeDevice: (id: string) => void;
  reset: () => void;
};

export const useDeviceLimitStore = create<DeviceLimitState>((set) => ({
  visible: false,
  devices: [],
  max: 0,
  plan: 'free',

  show: (devices, max, plan) => set({ visible: true, devices, max, plan }),
  hide: () => set({ visible: false }),
  removeDevice: (id) =>
    set((s) => ({ devices: s.devices.filter((d) => d.id !== id) })),

  reset: () => set({ visible: false, devices: [], max: 0, plan: 'free' }),
}));
