//
//  Utility.h
//  iHMS
//
//  Created by Weikang Ding on 10-11-2.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GDataXMLNode.h"
#import "DBQuery.h"
#import "GridData.h"
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "WebQuery.h"
#import <CoreLocation/CoreLocation.h>
#import "Reachability.h"
#import "R5NONCONFORMITIESHEADER.h"

@class R5FLEETBOOKLABOR;
@protocol PopOverDelegate

-(void)dismissPopOver;

@end

#pragma mark -
typedef NS_ENUM(NSUInteger, EAMAppType)
{
    EAMAppTypeTransit = 0,
    EAMAppTypeTransitMDM,
    EAMAppTypeFleet,
    EAMAppTypeFleetMDM,
    EAMAppTypeManufacture,
    EAMAppTypeManufactureMDM,
    EAMAppTypeEAMTransitABM,
    EAMAppTypeEAMTransitABMMTA
};



@interface Utility : NSObject {

}

//cursor function
+(void)showCursor:(UIView *)parentView andMsg:(NSString *)message;
+(void)showCursor:(UIView *)parentView IsOpaque:(BOOL)isOpaque;
+(void)hideCursor:(UIView *)parentView;

//Alert function
+(void)showAlert:(NSString *)error;
+(void)showAlert:(NSString *)error  target:(id)delegate;
+(BOOL)showAlertYesNo:(NSString *)message target:(id)delegate;
+(BOOL)showAlertOkCancel:(NSString *)message target:(id)delegate;
+(BOOL)showAlertYesNoCancel:(NSString *)message target:(id)delegate;
+(void)showAlert:(NSString *)error buttons:(NSArray *)buttonTitles tag:(int)tag delegate:(id)delegate;
+(BOOL)showAlertYesCancel:(NSString *)message target:(id)delegate;

//DateTime converting function
+(NSString *)dateToString:(NSDate *)dateValue type:(NSString *)dateType;
+(NSDate *)stringToDate:(NSString *)stringValue type:(NSString *)dateType;
+ (NSDate *)stringToDate:(NSString *)stringValue;
+(NSDate *)ISOStringToDate:(NSString *)stringValue type:(NSString *)dateType;
+(NSDate *)isDate:(id)value;
+(int)daysBetweenStart:(NSDate *)dt1 end:(NSDate *)dt2;
+(NSDate *)removeTimeFromNSDate:(NSDate *)date;
+(NSDate *)addTime:(long)time Unit:(NSString *)unit To:(NSDate *)date;

+(NSString *)valueOfElementPath:(NSString *)xPath inXML:(NSString *)xml;

//GDataXML functions
+(NSString *)valueOfStringForPath:(NSString *)xPath inNode:(GDataXMLNode *)node;
+(NSDate *)valueOfDateForPath:(NSString *)xPath  type:(NSString *)dateType inNode:(GDataXMLNode *)node;
+(NSNumber *)valueOfNumberForPath:(NSString *)xPath  type:(NSString *)numType inNode:(GDataXMLNode *)node;

+(BOOL)updateNodeValue:(GDataXMLNode *)node forPath:(NSString *)xPath value:(NSString *)value;
+(BOOL)updateDateNodeValue:(GDataXMLNode *)node forPath:(NSString *)xPath value:(NSDate *)dateValue;
+(BOOL)updateTimeNodeValue:(GDataXMLNode *)node forPath:(NSString *)xPath value:(NSDate *)timeValue;
// Added updateTimeNodeValue2 to handle end time in hours to allow 24
+(BOOL)updateTimeNodeValue2:(GDataXMLNode *)node forPath:(NSString *)xPath value:(NSDate *)timeValue;
+(BOOL)updateNumberNodeValue:(GDataXMLNode *)node forPath:(NSString *)xPath value:(NSNumber *)numberValue;

+(BOOL)addNode:(GDataXMLNode *)node xml:(NSString *)xmlString;
+(BOOL)addDateNode:(GDataXMLNode *)node name:(NSString *)nodeName value:(NSDate *)dateValue;
+(BOOL)addNumberNode:(GDataXMLNode *)node name:(NSString *)nodeName qualifier:(NSString *)qualifierAttribute value:(NSNumber *)numberValue;

+(NSString *)numberToXMLString:(NSString *)nodeName qualifier:(NSString *)qualifierAttribute value:(NSNumber *)numberValue;
+(NSString *)truncateNumberString:(NSString *)numStrValue;
+(NSString *)number2ToXMLString:(NSString *)nodeName qualifier:(NSString *)qualifierAttribute value:(NSNumber *)numberValue;
+(NSString *)dateToXMLString:(NSString *)nodeName value:(NSDate *)dateValue;
+(NSString *)timeToXMLString:(NSString *)nodeName value:(NSDate *)timeValue;
// Added timeToXMLString2 to handle end time in hours to allow 24
+(NSString *)timeToXMLString2:(NSString *)nodeName value:(NSDate *)timeValue;
+(NSString *)valueOfElement:(NSArray *)elementNames inXML:(NSString *)xml atLevel:(int)level;

+(UIBarButtonItem *)navButtonWithTitle:(NSString *)title width:(int)width target:(id)target action:(SEL)action;
+(UIBarButtonItem *)navButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action;
+(UIBarButtonItem *)navButtonWithIcon:(UIImage *)image target:(id)target action:(SEL)action;

+ (void)displayErrorMessage:(NSString *)errorMessage withTitle:(NSString *)title;
+ (NSString *)generateUniqueNumber;
+(NSString *)truncateNumberString:(NSNumber *)numValue maxdigits:(int)numOfDigits __deprecated;

//+ (NSString *) stringByUrlEncoding:(NSString *)value;
+(NSString *)docDirectory;
+(NSString *)cacheDirectory;
+(BOOL)writeArrayToFile:(NSString *)fileName array:(NSArray *)array;
+(NSMutableArray *)readArrayFromFile:(NSString *)fileName;
+(BOOL)writeDictionaryToFile:(NSString *)fileName dict:(NSDictionary *)dict;
+(NSMutableDictionary *)readDictionaryFromFile:(NSString *)fileName;
+(NSString *)getFileType:(NSString*)fileName;
+(BOOL)writeDictionaryToFile:(NSString *)fileName dict:(NSDictionary *)dict isTemp:(BOOL)isTemp;
+(NSMutableDictionary *)readDictionaryFromFile:(NSString *)fileName isTemp:(BOOL)isTemp;
+(BOOL)isEmptyString:(NSString *)str;
+(BOOL)isEqualString1:(NSString *)string1 string2:(NSString *)string2;
+(BOOL)isTrueString:(NSString *)value ;

+(BOOL)isEmptyNumber:(NSNumber *)number;
+ (BOOL ) parseFloat:(NSString *)string;
+ (BOOL ) parseDouble:(NSString *)string;
+ (BOOL ) parseInt:(NSString *)string;

+ (NSString *)dateToString:(NSDate *)date dateFormat:(NSString *)format andLocale:(NSString *)locale;
+(NSString *)dateToString:(NSDate *)dateValue;
+ (NSString *)getCodeDesc:(NSString *)code andEntity:(NSString *)entityDesc;
+ (NSMutableDictionary *)getCodeDescForEntity:(NSString *)entity;
+ (NSString *)getCodeDesc:(NSString *)code andEntity:(NSString *)entityDesc anSystemCode:(NSString *)systemCode;
+ (NSString *)getCodeRCode:(NSString *)code andEntity:(NSString *)entity;

+ (NSString *)getUCode:(NSString *)rcode andEntity:(NSString *)entity;
+ (NSString *)getCodeColor:(NSString *)rcode andEntity:(NSString *)entity;

+ (NSString *)getClassDesc:(NSString *)class classOrg:(NSString *)classOrg classEntity:(NSString *)classEntity;
+ (NSString *)getEquipmentClassDesc:(NSString *)class classOrg:(NSString *)classOrg obrType:(NSString *)obRType;
+ (NSString *)getCategoryDesc:(NSString *)category;

+ (int)getTimeoutInterval;
+ (NSString *)getOrgGroup;

+ (void)showLocalNotification:(NSString *)message onTheView:(UIView *)view;
+ (void)showLocalNotification:(NSString *)message onTheView:(UIView *)view forInterval:(NSTimeInterval )interval;
+ (void)showMapViewNotification:(NSString *)message  forInterval:(NSTimeInterval )interval;
+(BOOL)addSigatureToPDF:(UIView *)signatureView forPages:(int)forPages fromPDF:(NSString *)fromFile toPDF:(NSString *)toFile;
+ (NSString *) stringByUrlEncoding:(NSString *)value;
+ (NSString *) stringByXMLEncoding:(NSString *)value;
+ (NSString *) stringByHTMLDecoding:(NSString *)value;
+ (NSString *) stringByXMLEncodingForLOV:(NSString *)value;
+ (NSString *) getEntity:(NSString *)rentity;
+ (NSString *) BOOLToEAMBool:(BOOL)value;
+ (NSString *) stringToEAMBool:(NSString *)value;
+ (BOOL)stringToBool:(NSString *) value;
+ (NSString *)getINCRLINO:(NSString *)code;
+ (NSString *)getInstallParameterValue:(NSString *)code;
+ (NSString *)appServerURL;

+ (BOOL) enableFeatureForVersion:(NSString *)version;
+ (BOOL) enableFeatureForVersion:(NSString *)version andBuild:(NSString *)build;
+ (void)closeMainViewController;
+ (void)mainViewControllerClosed;
+ (UIView *)navigationTitle:(NSString *)title;

+ (UIView *)generateBadgeAt:(CGPoint)centerPoint withText:(NSString *)badgeText;
+ (UIView *)generateBadgeAt:(CGPoint)centerPoint withText:(NSString *)badgeText withColor:(UIColor *)color;
+ (NSString *)getAppSetting:(NSString *)setting;
+ (void)setAppSetting:(NSString *)setting withValue:(NSString *)value;
+ (NSString *)stringWithFormatForQuery:(NSString *)format;

+ (UIImage *)imageWithImage:(UIImage *)image resizeFactor:(float)factor;
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize;
+ (void)tintImageView:(UIImageView *)imageView imageName:(NSString *)imageName color:(UIColor *)tintColor;
+ (UIImage *)normalizedImage:(UIImage *)image;

+ (NSDate *)currentEAMServerDate;
+ (NSDate *)currentOrgDate;
+ (NSDate *)currentOrgDateOnly;

+ (BOOL)laterThanOrgDate:(NSDate *)dt;
+ (BOOL)laterThanOrgDateWithDataCompare:(NSDate *)dt;
+ (NSString *)appLogPath;
+ (NSString *)addFiltersTo:(NSString *)sql withParameters:(WebQueryParameters *)parameters;
+ (NSComparisonResult )compareDatesWithoutTime:(NSDate *)date1 anotherDate:(NSDate *)date2;

+ (NSArray *)getPropertyKeysForClass:(Class )cls;
+ (NSData *)serializeObject:(id)object;
+ (id)deSerializeObject:(NSData *)data forTheModel:(NSString *)modelName;
+ (id)createObjectFromDictionary:(NSDictionary *)dictObject forTheModel:(NSString *)modelName;
+ (UIImage *)imageWithColor:(UIColor *)color;
+ (NSString *)getAppVersion;
+ (int)getCodeVersion;
+ (int)getServerScriptVersion;
+ (CLLocationDirection)directionToLocation:(CLLocationCoordinate2D )coord1 coordinate:(CLLocationCoordinate2D )coord2;
+ (NSString *)getUniqueIdentifier;
+ (UIView *)findUITableViewCell:(UIView *)supView;
+ (float)iOSVersion;
+ (BOOL)isAppRunningForTheFirstTime;

+ (NSString *)isMecParentWorkOrder:(NSString *)woNum;
+ (NSDate *)workOrderStartDate:(NSString *)woNum;
+ (NSDate *)workOrderEndDate:(NSString *)woNum;

+ (NSString *)hasMultiChildClosed:(NSString *)woNum;
+ (NSString *)hasAllMultiChildClosed:(NSString *)woNum;
+ (NSString *)getstrfromstrField:(NSString *)value;
+ (NSString *)getParentWO:(NSString *)value;
+ (UIColor *)colorWithHexString:(NSString *)str;
+ (BOOL)compareID:(NSString *)mainID withTempID:(NSString *)tempID orWithPermID:(NSString *)permID;
+ (NSString *)getLinearReferenceUOM:(NSString *)object forOrg:(NSString *) org;
+ (NSDecimalNumber *)getObjectLength:(NSString *)object forOrg:(NSString *) org;
+ (NSString *) getVMRSDescSysLevel:(NSString *)sysLevel  asmLevel:(NSString *)asmLevel compLevel:(NSString *)compLevel;
+ (NSMutableDictionary *)getHeaderObjectLinearInformationForWO:(NSString *)evt_code;
+(NSString *)truncateNumberString:(NSNumber *)numValue maxdigits:(int)numOfDigits roundingMode:(NSRoundingMode *) pRoundingMode __deprecated;;

+ (void)clearNotifications;
+ (void)setReachability:(NetworkStatus *)networkStatus;
+ (BOOL)isNetworkAvailable;
+ (BOOL)isEAMServerReachableNow;
+ (BOOL)cameraAccessDenied;
+ (NSString *)getResolutionDescForCode:(NSString *)pCode;
+ (NSString *) getWoOrgOption: (NSString *)pType;
+ (BOOL) useLegacyNonconformity;
+ (NSMutableDictionary *)getObjectFromToPoint:(NSString *)pObject forOrg:(NSString *)pOrg;

+(NSNumber *) numberWithString:(NSString *) numberString;
+ (void)createScreenRendererSection:(NSString *)sectionName keysAndValues:(NSDictionary *)keysAndValues andJSONObject:(NSMutableDictionary *)jsonObject forScreen:(NSString *) pScreen;
+ (NSString *)getDepartmentDesc:(NSString *)department;
+ (NSNumber *)getUOMConversionValue:(NSString *)fromUOM toUOM:(NSString *)toUOM;
+ (NSString *)getObjectDirection:(NSString *)pObject forOrg:(NSString *)pOrg;
+ (NSMutableDictionary *)getLinearReferenceDetailsForReferedPoint:(NSString *)pReferenceId;
+(NSString *) getLinearReferencePointDescription:(NSString *)pReferenceId;
+(NSString *) getAlternatePointString :(double) vPoint;
+(NSString *) getAlternatePointString :(double) vPoint enabled:(BOOL)enabled parenthesis:(BOOL)parenthesis;
+(NSMutableDictionary *)getJSIUserPermissions :(NSString *)pUserCode;
+(NSMutableDictionary *)getUserResponsibilities :(NSString *)pUserCode;
+(BOOL)isValidUserResponsibility :(NSString *)pRespCode;
+(void) setLoginUserCommentsEditPermissions;

+ (UIView *)createCommentLabelWithText:(NSString *)text modified:(NSString *)modified withLabelWidth:(CGFloat )labelWidth;
+ (UIImage *)getImageFromUsersDocuments:(NSString *)imageFileName;
+ (UIImage *)getImageFromUsersVideo:(NSString *)videoFileName;

+ (float )getDeviceBatteryPercentage;
+ (double )convertGISMapUnits:(int )rawValue;
+(NSString *) getNonConformityTypeDesc:(NSString *)checkListCode ncfCode:(NSString *)ncfCode;
+ (NSString *)getMobileFirstScreen;
+(NSString *) getFirstConditionAsFound:(NSString *)pForWo actCode:(NSString *)pAct;
+ (BOOL)validateDocumentSize:(NSString *)fileName;

+ (EAMAppType)currentEAMAppType;
+ (NSString *)getURLPreFixForCurrentApp;

+ (NSDictionary *)getEntityMappings;
+ (NSString *)translateTempId:(NSString *)tempId;
+ (void)storeTempId:(NSString *)key value:(NSString *)value;
+ (NSString *)generateTempIDForEntity:(NSString *)entity;
+ (NSString *)getCurrencyCode;
+ (BOOL)isHTMLString:(NSString *)text;
+ (NSString *)fixHTMLScalling:(NSString *)inputHTML;

//type can be NUM/INT
+ (BOOL)validateDecimalNumberInput:(NSString *)input type:(NSString *)type;
// pass numberOfDigits as 0 for keeping all precision
// This method is to convert localized number to actuall number so that it will be saved in the local database
+ (NSString *)formatNumberForSaving:(NSString *)strNumber withPrecision:(int )numberOfDigits;
// This Method is to convert number to localized format for displaying the number in localized format
+ (NSString *)formatNumberForDisplay:(NSString *)strNumber withPrecision:(int )numberOfDigits;

+ (UIColor *)colorForPriority:(NSString *)priorityCode andEntity:(NSString *)entity;

+ (NSString *) getFullAPIURIFromHost:(NSString *) hostname endpoint:(NSString *) endpoint;
+ (NSMutableDictionary *)prepareIONServerConfigDisctionary:(NSDictionary *)discConfig;
+ (BOOL)validateMingleBarCodeForValidApp:(NSString *)appURL;
+ (NSString *)getMingleRedirectURL;
+ (BOOL )ionLoginConfigEmbededInMDM;
+ (BOOL )checkIfMDMConfigHasChangedForION:(NSDictionary *)currentLocalConfig mdmConfig:(NSDictionary *)mdmConfig;
+ (NSString *)getLevelDescriptionForCode:(NSString *)code org:(NSString *)org andLevel:(NSString *)level;
+ (NSString *)getObjectPrecision:(NSString *)pObject forOrg:(NSString *)pOrg;
+ (NSString *)getObjectRType:(NSString *)pObject forOrg:(NSString *)pOrg;
+ (void)clearNetworkCache;
+ (BOOL)useNewSyncProcess;
+ (float)cpu_usage;
+ (NSString *)memory_usage;
+ (NSString *)getUserDescription:(NSString *)pUserCode;
+ (NSString *)getUserAutoSyncValue:(NSString *)pUserCode;
+ (NSString *)getUserDepartment:(NSString *)pUserCode;
+ (NSString *)getLinearUOMDesc:(NSString *)code;
+(GridData *) getAllChildrens:(NSString *)pLeaf forOrg:(NSString *) pLeafOrg;
+(BOOL) validateMobileEntitySetup:(NSString *)pEntity;
+(BOOL) isSVersionMOBENTTYParamMatch;
+ (NSArray *)calculateTimerHoursMinForStartStop:(R5FLEETBOOKLABOR *)pFleetModel;
+ (BOOL) enableStartStopActivityFeature;
+(NSDate *) currentOrgDateWithoutMilliSec;
+ (NSString *) getDisplayTimeHoursMin:(NSDecimalNumber *) timeMilleSeconds;
+(id) validateFleetForWorkedTime :(R5FLEETBOOKLABOR *) pFleetRecord;
+ (void) clearGISCredentials;
+(UIImage *)resizeImage:(UIImage *)sourceImage toSize:(NSString *)target;
+(CGFloat *)sizeOfImage:(UIImage *)sourceImage forSize:(NSString *)target;
//+(NSString *)getUOMDesc:(NSString *)code;
+ (void) deleteUserData: (BOOL) includeBasemap;
extern NSString *const  axis_url_template;
extern NSString *const  soapHeader_template;
extern NSString *const  soapFooter;
extern NSString *const  SECTION_TYPE_CONSTANT_CHILD_LIST_VIEW;
extern NSString *const  SECTION_TYPE_CONSTANT_NORMAL;
extern NSString *const  SECTION_TYPE_CONSTANT_BUTTON;
extern NSString *const  SECTION_TYPE_CONSTANT_LOCATION;
extern NSString *const  SECTION_TYPE_CONSTANT_COMMENTS;
extern NSString *const  SECTION_TYPE_CONSTANT_DOCUMENTS;
extern NSString *const  SECTION_TYPE_CONSTANT_ATTACHMENTS;
extern NSString *const  WebServiceCalled;
extern NSString *const  WebServiceResponseReceived;


typedef enum
{
    RecordCellFieldTypeEditableText,
    RecordCellFieldTypeReadOnlyText,
    RecordCellFieldTypeLOV,
    RecordCellFieldTypeDateTime,
    RecordCellFieldTypeYesNo
}RecordCellFieldType;

typedef enum
{    
    WorkOrderChildTypeWONumber,
    WorkOrderChildTypeActivities,
    WorkOrderChildTypeComments,
    WorkOrderChildTypeIssueReturnParts,
    WorkOrderChildTypeBookLabor,
    WorkOrderChildTypePrintWorkOrder
}WorkOrderChildType;
typedef enum
{    
    EquipmentChildTypeEquipNumber,
    EquipmentChildTypeEquipHistory,
    EquipmentChildTypeEquipComments
}EquipmentChildType;

typedef enum
{
    AnnotationTypeWorkOrder,
    AnnotationTypeEquipment
}AnnotationType;

typedef enum
{
    ReportTypeWorkOrderComprehensive,
    ReportTypeWorkOrderProofOfDelivery
}ReportType;


typedef enum
{
    ActivityChildTypeActivity,
    ActivityChildTypeComment,
    ActivityChildTypeTaskInstructions,
    ActivityChildTypePMComments,
    ActivityChildTypeInspectionTasks,
    ActivityChildTypeChecklistApproval
}ActivityChildType;

typedef enum {
    SyncStatusNone,
    SyncStatusStart,
    SyncStatusComplete,
    SyncStatusStop,
    SyncStatusAbort
} SyncStatus;

typedef enum
{
    LocationPointTypeWorkOrder,
    LocationPointTypeEquipment,
    LocationPointTypeUser
}LocationPointType;

@end
