/**
 * DailyNotification Bridge Contract
 * 
 * TypeScript interface definitions for the DailyNotification plugin
 * Provides type safety and schema validation at the JavaScript boundary
 * 
 * @author Matthew Raymer
 * @version 1.0.0
 */

// Core plugin interface
export interface DailyNotificationBridge {
  scheduleDailyNotification(request: ScheduleRequest): Promise<ScheduleResponse>
  checkPermissions(): Promise<PermissionStatus>
  getNotificationStatus(): Promise<NotificationStatus>
  getExactAlarmStatus(): Promise<ExactAlarmStatus>
  requestPermissions(): Promise<PermissionResult>
  openExactAlarmSettings(): Promise<void>
  openChannelSettings(): Promise<void>
  requestBatteryOptimizationExemption(): Promise<void>
  cancelAllNotifications(): Promise<void>
  getLastNotification(): Promise<NotificationContent | null>
}

// Request/Response schemas
export interface ScheduleRequest {
  time: string        // HH:mm format (24-hour)
  title: string       // max 100 chars
  body: string        // max 500 chars
  sound: boolean      // play sound
  priority: 'low' | 'default' | 'high'
}

export interface ScheduleResponse {
  success: boolean
  scheduledAt?: number
  error?: ErrorInfo
}

export interface PermissionStatus {
  notifications: 'granted' | 'denied'
  notificationsEnabled: boolean
  exactAlarmEnabled?: boolean
  wakeLockEnabled?: boolean
  allPermissionsGranted?: boolean
}

export interface NotificationStatus {
  isEnabled: boolean
  isScheduled: boolean
  lastNotificationTime?: number
  nextNotificationTime?: number
  pending: boolean
  error?: string
}

export interface ExactAlarmStatus {
  enabled: boolean
  supported: boolean
}

export interface PermissionResult {
  granted: boolean
  permissions: PermissionStatus
}

export interface NotificationContent {
  id: string
  title: string
  body: string
  scheduledTime: number
  mediaUrl?: string
  fetchTime: number
}

export interface ErrorInfo {
  code: string
  message: string
  hint?: string
}

// Validation schemas
export interface ValidationResult {
  isValid: boolean
  errors: string[]
  message: string
}

// Error codes (canonical)
export enum ErrorCode {
  INVALID_TIME = 'E_INVALID_TIME',
  TITLE_TOO_LONG = 'E_TITLE_TOO_LONG',
  BODY_TOO_LONG = 'E_BODY_TOO_LONG',
  PERMISSION_DENIED = 'E_PERMISSION_DENIED',
  CHANNEL_DISABLED = 'E_CHANNEL_DISABLED',
  EXACT_ALARM_DENIED = 'E_EXACT_ALARM_DENIED',
  DOZE_LIMIT = 'E_DOZE_LIMIT',
  CHANNEL_MISSING = 'E_CHANNEL_MISSING',
  BAD_CONFIG = 'E_BAD_CONFIG',
  RESPONSE_TOO_LARGE = 'E_RESPONSE_TOO_LARGE',
  INSECURE_URL = 'E_INSECURE_URL',
  SCHEDULE_BLOCKED = 'E_SCHEDULE_BLOCKED'
}

// Plugin instance type
export type DailyNotificationPlugin = DailyNotificationBridge

// Utility types
export type StatusType = 'success' | 'warning' | 'error' | 'info'
export type PriorityType = 'low' | 'default' | 'high'
export type PermissionType = 'granted' | 'denied'
