1 /* 2 * Copyright 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.appfunctions.metadata 18 19 import androidx.annotation.RestrictTo 20 import androidx.appsearch.annotation.Document 21 22 /** Represent a function parameter. */ 23 public class AppFunctionParameterMetadata( 24 /** The name of the parameter. */ 25 public val name: String, 26 /** Determines whether this parameter is mandatory. */ 27 public val isRequired: Boolean, 28 /** The data type of the parameter. */ 29 public val dataType: AppFunctionDataTypeMetadata, 30 ) { equalsnull31 override fun equals(other: Any?): Boolean { 32 if (this === other) return true 33 if (javaClass != other?.javaClass) return false 34 35 other as AppFunctionParameterMetadata 36 37 if (name != other.name) return false 38 if (isRequired != other.isRequired) return false 39 if (dataType != other.dataType) return false 40 41 return true 42 } 43 hashCodenull44 override fun hashCode(): Int { 45 var result = name.hashCode() 46 result = 31 * result + isRequired.hashCode() 47 result = 31 * result + dataType.hashCode() 48 return result 49 } 50 toStringnull51 override fun toString(): String { 52 return "AppFunctionParameterMetadata(" + 53 "name=$name, " + 54 "isRequired=$isRequired, " + 55 "dataType=$dataType" + 56 ")" 57 } 58 59 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) toAppFunctionParameterMetadataDocumentnull60 public fun toAppFunctionParameterMetadataDocument(): AppFunctionParameterMetadataDocument { 61 return AppFunctionParameterMetadataDocument( 62 name = name, 63 isRequired = isRequired, 64 dataTypeMetadata = dataType.toAppFunctionDataTypeMetadataDocument() 65 ) 66 } 67 } 68 69 /** Represents the persistent storage format of [AppFunctionParameterMetadata]. */ 70 @Document 71 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 72 public data class AppFunctionParameterMetadataDocument( 73 @Document.Namespace public val namespace: String = APP_FUNCTION_NAMESPACE, 74 @Document.Id public val id: String = APP_FUNCTION_ID_EMPTY, 75 @Document.StringProperty public val name: String, 76 @Document.BooleanProperty public val isRequired: Boolean, 77 @Document.DocumentProperty public val dataTypeMetadata: AppFunctionDataTypeMetadataDocument 78 ) { toAppFunctionParameterMetadatanull79 public fun toAppFunctionParameterMetadata(): AppFunctionParameterMetadata = 80 AppFunctionParameterMetadata( 81 name = name, 82 isRequired = isRequired, 83 dataType = dataTypeMetadata.toAppFunctionDataTypeMetadata() 84 ) 85 } 86