/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import * as Code from '../code' ; import * as Error from '../error' ; import * as FileWriter from '../file-writer' ; import * as CLangCommon from '../clang-common' ; import * as ObjC from '../objc' ; import * as StringUtils from '../string-utils' ; import * as ObjectSpec from '../object-spec' ; import * as ObjectSpecHelpers from '../object-spec-helpers' ; import * as ObjectSpecUtils from '../object-spec-utils' ; function nameOfFetchStatusForValueTypeWithName ( valueTypeName ) { return valueTypeName + 'FetchStatus' ; } function nameOfFetchStatusAttributeForAttribute ( attributeName ) { return 'hasFetched' + StringUtils . capitalize ( attributeName ) ; } function isFetchStatusAttribute ( attribute , objectType ) { return ( attribute . type . name !== nameOfFetchStatusForValueTypeWithName ( objectType . typeName ) ) ; } function fetchStatusAttributeForAttribute ( attribute ) { return new ObjectSpecHelpers . AttributeBuilder ( nameOfFetchStatusAttributeForAttribute ( attribute . name ) , new ObjectSpecHelpers . AttributeTypeBuilder ( 'BOOL' , 'BOOL' , null ) ) . asObject ( ) ; } function fetchedAttributesForValueType ( objectType ) { return objectType . attributes . filter ( function ( attribute ) { return isFetchStatusAttribute ( attribute , objectType ) ; } ) . map ( fetchStatusAttributeForAttribute ) ; } function fetchStatusValueTypeForValueType ( objectType ) { return { annotations : { } , attributes : fetchedAttributesForValueType ( objectType ) , comments : [ ] , excludes : [ ] , includes : [ ] , libraryName : objectType . libraryName , typeLookups : [ ] , typeName : nameOfFetchStatusForValueTypeWithName ( objectType . typeName ) } ; } function fetchStatusAttributeForValueType ( objectType ) { const fetchStatusTypeName = nameOfFetchStatusForValueTypeWithName ( objectType . typeName ) ; return new ObjectSpecHelpers . AttributeBuilder ( 'fetchStatus' , new ObjectSpecHelpers . AttributeTypeBuilder ( fetchStatusTypeName , ObjectSpecUtils . typeReferenceForValueTypeWithName ( fetchStatusTypeName ) , 'NSObject' ) . withLibraryTypeIsDefinedIn ( objectType . libraryName ) ) . asObject ( ) ; } export function createPlugin ( ) { return { additionalFiles : function ( objectType ) : Code . File [ ] { return [ ] ; } , transformBaseFile : function ( objectType , baseFile ) : Code . File { return baseFile ; } , additionalTypes : function ( objectType ) : ObjectSpec . Type [ ] { return [ fetchStatusValueTypeForValueType ( objectType ) ] ; } , attributes : function ( objectType ) : ObjectSpec . Attribute [ ] { return [ fetchStatusAttributeForValueType ( objectType ) ] ; } , classMethods : function ( objectType ) : ObjC . Method [ ] { return [ ] ; } , transformFileRequest : function ( request ) : FileWriter . Request { return request ; } , fileType : function ( objectType ) : Code . FileType | null { return null ; } , forwardDeclarations : function ( objectType ) : ObjC . ForwardDeclaration [ ] { return [ ] ; } , functions : function ( objectType ) : ObjC . Function [ ] { return [ ] ; } , headerComments : function ( objectType ) : ObjC . Comment [ ] { return [ ] ; } , implementedProtocols : function ( objectType ) : ObjC . ImplementedProtocol [ ] { return [ ] ; } , imports : function ( objectType ) : ObjC . Import [ ] { return [ ] ; } , instanceMethods : function ( objectType ) : ObjC . Method [ ] { return [ ] ; } , macros : function ( valueType ) : ObjC . Macro [ ] { return [ ] ; } , properties : function ( objectType ) : ObjC . Property [ ] { return [ ] ; } , requiredIncludesToRun : [ 'RMFetchStatus' ] , staticConstants : function ( objectType ) : ObjC . Constant [ ] { return [ ] ; } , validationErrors : function ( objectType ) : Error . Error [ ] { return [ ] ; } , nullability : function ( objectType ) : ObjC . ClassNullability | null { return null ; } , subclassingRestricted : function ( objectType ) : boolean { return false ; } } ; }