import { NativeModules, Platform } from 'react-native';

const { LiveActivityModule } = NativeModules;

export const LiveActivity = {
  /**
   * 开始位置监听 Live Activity
   * @returns {Promise<void>}
   */
  startLocationActivity: async () => {
    if (Platform.OS !== 'ios') {
      console.warn('Live Activities only available on iOS');
      return;
    }
    
    try {
      await LiveActivityModule?.startLocationActivity();
    } catch (error) {
      console.error('Failed to start Live Activity:', error);
    }
  },

  /**
   * 停止位置监听 Live Activity
   * @returns {Promise<void>}
   */
  stopLocationActivity: async () => {
    if (Platform.OS !== 'ios') {
      console.warn('Live Activities only available on iOS');
      return;
    }
    
    try {
      await LiveActivityModule?.stopLocationActivity();
    } catch (error) {
      console.error('Failed to stop Live Activity:', error);
    }
  },

  /**
   * 检查设备是否支持 Live Activities
   * @returns {boolean}
   */
  isSupported: () => {
    return Platform.OS === 'ios' && LiveActivityModule != null;
  }
};

export default LiveActivity;