public with sharing class RentalReportExportController {
    public List<SelectOption> objectOptions{set;get;}
    public List<SelectOption> contactOptions{set;get;}
    public List<SelectOption> filedOptions{set;get;}
    public List<SelectOption> operationSelectOptions{set;get;}
    public List<InputFilter> fieldInputList{set;get;}
    public String staticResource {get; set;}
    public String staticResourceContact {get; set;}
    public Boolean isContactAll {get; set;}
    public String selectedObject{set;get;}
    public Integer fieldSize{get; set;}
    public RentalReportExportController() {
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Rental_Apply__c')); 
        staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));     
        fieldInputList = new List<InputFilter>();
        InputFilter ifilter = new InputFilter();
        ifilter.fieldAPI = 'sfRecordId';
        ifilter.operation = 'in';
        ifilter.value = '';
        fieldInputList.add(ifilter);
        fieldSize = fieldInputList.size();
        System.debug('fieldSize ' + fieldSize);
        getAwsField();
        objectOptions = new List<SelectOption>();
        contactOptions = new List<SelectOption>();
        SelectOption so = new SelectOption('Rental_Apply__c','备品发货地');
        objectOptions.add(so);
        contactOptions.add(new SelectOption('Contact','客户人员'));
        operationSelectOptions = new List<SelectOption>();
        operationSelectOptions.add(new SelectOption('like','包含'));

        isContactAll = false;
        System.debug('isContactAll ' + isContactAll);
        User users = [select Id, Profile.UserType, Profile.UserLicense.Name from User Where Id =:UserInfo.getUserId()];
        System.debug('users: ' + users);
        Profile profiles = [select Id, UserType, UserLicense.Name, Name from Profile Where Id =:users.ProfileId];
        System.debug('profiles: ' + profiles);
        // PermissionSet permissionSet = [select Profile.Name, Id, ProfileId from PermissionSet where ProfileId =:profiles.Id];
        // System.debug('permissionSet: ' + permissionSet);
        // ObjectPermissions objectPermission = [select ParentId, PermissionsViewAllRecords, PermissionsRead from ObjectPermissions Where SObjectType = 'Contact' and ParentId =:permissionSet.Id limit 1];
        // System.debug('objectPermission: ' + objectPermission);
        if(profiles.Name == '系统管理员'){
            isContactAll = true;
        }  
        System.debug('isContactAll ' + isContactAll);

    }

    public void getAwsField(){
        // List<PI_Field_Policy_Detail__c> contactField = [select id, PI_Policy_Configuration__r.Sobject_Type__c, SF_Field_API_Name__c, SF_Field_Name__c, AWS_Field_API__c from PI_Field_Policy_Detail__c where PI_Policy_Configuration__r.Sobject_Type__c = 'Contact'];
        filedOptions = new List<SelectOption>();
        filedOptions.add(new SelectOption('sfRecordId', 'ID'));
        // for (PI_Field_Policy_Detail__c piField : contactField) {
        //     filedOptions.add(new SelectOption(piField.AWS_Field_API__c, piField.SF_Field_Name__c));
        // }
        System.debug('filedOptions ' + filedOptions);
    }

    public PageReference addFilter(){
        InputFilter ifilter = new InputFilter();
        ifilter.fieldAPI = 'lastName';
        ifilter.operation = 'Equals';
        ifilter.value = '';
        fieldInputList.add(ifilter);
        System.debug('fieldInputList add ' + fieldInputList);
        fieldSize = fieldInputList.size();
        System.debug('fieldSize ' + fieldSize);
        return null;
    }

    
    public PageReference removeFilter(){
        System.debug('fieldInputList remove ' + fieldInputList);
        fieldInputList.remove(fieldInputList.size() - 1);
        fieldSize = fieldInputList.size();
        System.debug('fieldSize ' + fieldSize);
        return null;
    }

    public class InputFilter{
        public String fieldAPI{set;get;}
        public String operation{set;get;}
        public String value{set;get;}
    }
}