//
//  LNPermissionHelper.swift
//  Lanu
//
//  Created by OneeChan on 2026/03/08.
//

import Foundation
import Photos
import AVFoundation
import AVFAudio
import UserNotifications

struct LNPermissionHelper {
    static func requestPhotoLibraryAuthorization(_ completion: @escaping (PHAuthorizationStatus) -> Void) {
        PHPhotoLibrary.requestAuthorization { status in
            runOnMain {
                completion(status)
            }
        }
    }

    static func cameraAuthorizationStatus() -> AVAuthorizationStatus {
        AVCaptureDevice.authorizationStatus(for: .video)
    }

    static func requestCameraAccess(_ completion: @escaping (Bool) -> Void) {
        AVCaptureDevice.requestAccess(for: .video) { granted in
            runOnMain {
                completion(granted)
            }
        }
    }

    static func microphonePermission() -> AVAudioSession.RecordPermission {
        AVAudioSession.sharedInstance().recordPermission
    }

    static func requestMicrophoneAccess(_ completion: @escaping (Bool) -> Void) {
        AVAudioSession.sharedInstance().requestRecordPermission { granted in
            runOnMain {
                completion(granted)
            }
        }
    }

    static func requestNotificationAuthorization(options: UNAuthorizationOptions,
                                                 completion: @escaping (Bool, Error?) -> Void) {
        UNUserNotificationCenter.current().requestAuthorization(options: options) { granted, error in
            runOnMain {
                completion(granted, error)
            }
        }
    }

    static func fetchNotificationSettings(_ completion: @escaping (UNNotificationSettings) -> Void) {
        UNUserNotificationCenter.current().getNotificationSettings { settings in
            runOnMain {
                completion(settings)
            }
        }
    }
}
