public with sharing class RentalSequenceWatchController {
	public List<Rental_Apply_Sequence__c> rasShowCFList{get;set;}
	public List<Rental_Apply_Sequence__c> rasShowTHList{get;set;}
	public List<Rental_Apply_Equipment_Set_Detail__c> raesDShowCFList{get;set;}
	public List<Rental_Apply_Equipment_Set_Detail__c> raesDShowTHList{get;set;}

	public Boolean haveErrCF_X{get;set;}
	public Boolean haveErrTH_X{get;set;}
	public Boolean haveErrCF_D{get;set;}
	public Boolean haveErrTH_D{get;set;}
    public RentalSequenceWatchController() {
        haveErrCF_X = false;
        haveErrTH_X = false;
        haveErrCF_D = false;
        haveErrTH_D = false;
        rasShowCFList = new List<Rental_Apply_Sequence__c>();
        rasShowTHList = new List<Rental_Apply_Sequence__c>();
        raesDShowCFList = new List<Rental_Apply_Equipment_Set_Detail__c>();
		raesDShowTHList = new List<Rental_Apply_Equipment_Set_Detail__c>();
    }
    public void init(){
    	Map<String,String> esnMap = new Map<String,String>();
    	Map<String,String> ekeyMap = new Map<String,String>();
		List<Rental_Apply_Sequence__c> rasList = [Select Id,ExternalKey_Series_No__c, Series_No__c,ExternalKey__c From Rental_Apply_Sequence__c where Invalid_Flag__c = false order by ExternalKey__c,Series_No__c];
    	Integer i = 1;
    	for(Rental_Apply_Sequence__c ras:rasList){
    		if(esnMap.containsKey(ras.ExternalKey_Series_No__c)){
    			rasShowCFList.add(ras);
    		}else{
    			esnMap.put(ras.ExternalKey_Series_No__c,ras.ExternalKey_Series_No__c);
    		}
    		if(ekeyMap.containsKey(ras.ExternalKey__c)){
    			if(ekeyMap.get(ras.ExternalKey__c) == 'true'){
    				continue;
    			}
    			i++;
    		}else{
    			ekeyMap.put(ras.ExternalKey__c, 'false');
    			i = 1;
    		}
    		if(ras.Series_No__c <> i){
    			rasShowTHList.add(ras);
    			ekeyMap.put(ras.ExternalKey__c, 'true');
    		}
    	}
    	if(rasShowCFList.size() > 0 ){
    		haveErrCF_X = true;
    	}
    	if(rasShowTHList.size() > 0 ){
    		haveErrTH_X = true;
    	}
    	Map<String,String> esnDMap = new Map<String,String>();
    	Map<String,String> ekeyDMap = new Map<String,String>();
		List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [Select Id,Name, Queue_Number__c,ExternalKey__c From Rental_Apply_Equipment_Set_Detail__c 
												where Cancel_Select__c = false  and  Queue_Number__c > 0 order by ExternalKey__c,Queue_Number__c];
    	Integer ii = 1;
    	for(Rental_Apply_Equipment_Set_Detail__c raesd:raesdList){
    		String temp = raesd.ExternalKey__c + String.valueOf(raesd.Queue_Number__c);
    		if(esnDMap.containsKey(temp)){
    			raesDShowCFList.add(raesd);
    		}else{
    			esnDMap.put(temp,temp);
    		}
    		if(ekeyDMap.containsKey(raesd.ExternalKey__c)){
    			if(ekeyDMap.get(raesd.ExternalKey__c) == 'true'){
    				continue;
    			}
    			ii++;
    		}else{
    			ekeyDMap.put(raesd.ExternalKey__c, 'false');
    			ii = 1;
    		}
    		if(raesd.Queue_Number__c <> ii){
    			raesDShowTHList.add(raesd);
    			ekeyDMap.put(raesd.ExternalKey__c, 'true');
    		}
    	}
    	if(raesDShowCFList.size() > 0 ){
    		haveErrCF_D = true;
    	}
    	if(raesDShowTHList.size() > 0 ){
    		haveErrTH_D = true;
    	}
    }
    @TestVisible private void test() {
        Integer i = 0;
       
    }
}