import SwiftUI
import AppIntents

struct ChangeFavoriteIntent: AppIntent {
   static let title: LocalizedStringResource = "Change favorite"
   static let isDiscoverable: Bool = false

   @Dependency var appData: ApplicationData
   @Parameter
   var movie: MovieEntity

   init() {}
   init(movie: MovieEntity) {
       self.movie = movie
   }
   @MainActor
   func perform() async throws -> some IntentResult {
      if let index = appData.listMovies.firstIndex(where: { $0.id == movie.id }) {
         appData.listMovies[index].favorite.toggle()
      }
      return .result()
   }
}