//
//  Custom Fields.h
//  EAMiPad
//
//  Created by Lakshmi Kothapalli on 01/31/13.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DBQuery.h"
#import "LOVData.h"
#import "RecordDataController.h"
#import "EAMField.h"

@class CustomField;

typedef enum {
    CFTypeText = 0,
    CFTypeLOV,
    CFTypeNumber,
    CFTypeDate,
    CFTypeCode,
    CFTypeCodeDesc,
    CFTypeCheckBox
} CFType;

@interface CFIELDS : NSObject
@property (nonatomic, strong) NSString  *APR_LIST;
@property (nonatomic, strong) NSString  *APR_LISTVALID;
@property (nonatomic, strong) NSString  *APR_CLASS;
@property (nonatomic, strong) NSString  *APR_CLASSORG;
@property (nonatomic, strong) NSString  *APR_RENTITY;

@property (nonatomic, strong) NSString  *PRO_CODE;
@property (nonatomic, strong) NSString  *PRO_TYPE;
@property (nonatomic, strong) NSString  *PRO_TEXT;
@property (nonatomic, strong) NSString  *PRO_MIN;
@property (nonatomic, strong) NSString  *PRO_MAX;

@property (nonatomic, strong) NSString  *PRV_CODE;
@property (nonatomic, strong) NSString  *PRV_VALUE;
@property (nonatomic, strong) NSNumber  *PRV_NVALUE;
@property (nonatomic, strong) NSDate    *PRV_DVALUE;
@property (nonatomic, strong) NSString  *PRV_RENTITY;

@property (nonatomic, strong) NSString  *WSF_MOBILEQUERYCODE;

@property (nonatomic, strong) EAMField *CF_CONTROL;
@property (nonatomic, ) int CF_TYPE;
@property (nonatomic, strong) NSString *CF_PICKERQUERY;
@end


extern NSString * const CFD_CHAR;
extern NSString * const CFD_RENT;
extern NSString * const CFD_CODE;
extern NSString * const CFD_NUM;
extern NSString * const CFD_DATE;
extern NSString * const CFD_DATI;

typedef enum
{
    CFDEntityTypeWorkOrder,
    CFDEntityTypeEquipment,
    CFDEntityTypeLocation,
    CFDEntityTypeMobileNotebook,
    CFDEntityTypePermitToWork,
    CFDEntityTypeStandardWorkOrder,
    CFDEntityTypeNonconformity
}CFDEntityType;


typedef enum
{
    CFDTypeText,
    CFDTypeLOV,
    CFDTypeNumber,
    CFDTypeDate,
    CFDTypeDate1
    
}CFDType;


@interface CustomFields : NSObject
//+ (NSArray *)getCFieldsNegativeWSFLine:(NSString *)pmtCode;

//validation.begin
+ (BOOL)validateClass:(NSString *)sClass
          forClassOrg:(NSString *)classOrg
        forControlOrg:(NSString *)controlOrg
           forREntity:(NSString *)rEntity;

+ (BOOL)validateControlOrg:(NSString *)controlOrg;

+ (BOOL)validateCategory:(NSString *)category
                forClass:(NSString *)sClass
             forClassOrg:(NSString *)classOrg;
//validation.end

+ (NSString *)getPromptEntity:(NSString *)pmtCode
              forProcessGroup:(int)processGroup;

+ (NSDictionary *)dictionaryFromArray:(NSArray *)array;
+ (void)setReadOnly:(NSDictionary *)cFields forParent:(RecordDataController *)parent value:(BOOL)value;
+ (void)getCFWithPositiveLine:(NSString *)pmtCode;

+ (NSMutableArray *)getDefCustomFieldsforProceesGroup:(int)pGroup
                            forPromptCode:(NSString *)pmtCode;

+ (NSMutableArray *)getOrgCustomFieldsforProcessGroup:(int)pGroup
                            forPromptCode:(NSString *)pmtCode
                                 forControlOrg:(NSString *)controlOrg
                                     toCFArray:(NSMutableArray *)cFieldArray;


+ (NSMutableArray *)getClassOrgCustomFieldsforProcessGroup:(int)pGroup
                                             forPromptCode:(NSString *)pmtCode
                                               forClassOrg:(NSString *)classOrg
                                                  forClass:(NSString *)forClass
                                             forControlOrg:(NSString *)controlOrg
                                        andClassControlOrg:(NSString *)classControlOrg
                                                 toCFArray:(NSMutableArray *)cFieldArray;


//work order & equip
+ (NSString *)getDefaultOrg;
+ (NSMutableArray *)getDefCustomFields:(NSString *)code
                         forDefaultOrg:(NSString *)defaultOrg;
+ (NSMutableArray *)getOrgCustomFields:(NSString *)org
                               forCode:(NSString *)code
                        andloadCFArray:(NSMutableArray *)cFieldArray;

+ (NSMutableArray *)getClassCustomFields:(NSString *)classVal
                             forClassOrg:(NSString *)classOrg
                                 forCode:(NSString *)code
                          andloadCFArray:(NSMutableArray *)cFieldArray;

+ (NSArray *)sortCustomFields:(NSArray *)customFieldValues;

#pragma mark - Custom Fields

+ (NSMutableArray *)getCustomFieldsForEntity:(CFDEntityType )entityType
                                   andFields:(NSMutableArray *)cFieldArray;
+ (NSArray *)addCustomFieldKeys:(NSArray *)customFields to:(NSArray *)keys;
+ (NSArray *)addCustomFieldValues:(NSArray *)customFields to:(NSArray *)values;
+ (NSArray *)retainCustomFieldValues:(NSArray *)oldCustomFeilds andNewValues:(NSArray *)newCustomFieldValues;
+ (NSArray *)retainCustomFieldValuesForStandardWorkOrder:(NSArray *)oldCustomFeilds andNewValues:(NSArray *)newCustomFieldValues;
+ (NSDictionary *)customFieldsDictionaryFromArray:(NSArray *)array;
+ (LOVData *)getLOVDataForCustomField:(CustomField *)custField withDefaultValue:(NSString *)defaultValue;
+ (NSString *)getPickerQuery:(CustomField *)cfd forRentity:(NSString *)rentity;
+ (Boolean)isCustomFieldDataCleared:(NSArray *)oldCustomFields andNewValues:(NSArray *) newCustomFieldValues;
+ (BOOL)isCustomFieldRequied:(NSString *)cfCode forREntity:(NSString *)rEntity entityOrg:(NSString *)entityOrg customFieldClass:(NSString *)cls classOrg:(NSString *)clsOrg andStatus:(NSString *)status;
@end
