@Model
class Author: Identifiable {
   @Attribute(.unique) var id: UUID = UUID()
   var name: String = ""
   @Relationship(deleteRule: .nullify) var books: [Book]? = []
   var info: Data?
   
   init(name: String, books: [Book], info: Data?) {
      self.name = name
      self.books = books
      self.info = info
   }
   var listBooks: [Book] {
      get {
         let sortList = books?.sorted(by: { $0.title < $1.title }) ?? []
         return sortList
      }
   }
   @MainActor
   var showBirthday: String? {
      let decoder = PropertyListDecoder()
      if let info, let authorInfo = try? decoder.decode(AuthorInfo.self, from: info) {
         if let date = authorInfo.birthday, date < Date() {
            return authorInfo.birthday?.formatted(date: .abbreviated, time: .omitted)
         }
      }
      return nil
   }
   @MainActor
   var showPlaceOfBirth: String? {
      let decoder = PropertyListDecoder()
      if let info, let authorInfo = try? decoder.decode(AuthorInfo.self, from: info) {
         if !authorInfo.placeOfBirth.isEmpty {
            return authorInfo.placeOfBirth
         }
      }
      return nil
   }
}