public with sharing class LexAWSServicePIPLDao {
    public static List<Contact> searchContactInit(String HospitalId) {
        List<Contact> conList = new List<Contact>(
            [
                SELECT Id, AWS_Data_Id__c, Account.Name
                FROM Contact
                WHERE Account.Hospital__c = :HospitalId AND AWS_Data_Id__c != '' order by createddate desc limit 1000   //deloitte-zhj 20231113
            ]
        );
        return conList;
    }

    public static List<Contact>  getNoPIContact(String searchContactName,String accountId){
        if(searchContactName!='' || accountId!=''){
            String noPISQL = 'select Id,Name,Email,Phone,Account.Name,MobilePhone,AWS_Data_Id__c from Contact where Account_Record_Type_DeveloperName__c in('+'\'Agency\''+','+'\'Office\''+',\'AgencyContact\''+')';
            if(String.isNotEmpty(accountId)){
                noPISQL += ' and AccountId=\''+accountId+'\'';
            }
            if(String.isNotEmpty(searchContactName)){
                noPISQL += ' and Name like \'%'+searchContactName+'%\'';
            }
            system.debug('noPISQL = ' + noPISQL);
            List<Contact> partnerContactList = Database.query(noPISQL);
            return partnerContactList;
        }else{
            String noPISQL = 'select Id,Name,Email,Phone,Account.Name,MobilePhone,AWS_Data_Id__c from Contact where Account_Record_Type_DeveloperName__c in('+'\'Agency\''+','+'\'Office\''+',\'AgencyContact\''+') limit 100';
            system.debug('noPISQL = ' + noPISQL);
            List<Contact> partnerContactList = Database.query(noPISQL);
            return partnerContactList;
        }
    }


    public static List<Contact> searchContactInitNoAccountId() {
        List<Contact> conList = new List<Contact>(
            [
                SELECT Id, AWS_Data_Id__c, Account.Name
                FROM Contact
                WHERE  AWS_Data_Id__c != '' And Account.Name!=''limit 100
            ]
        );
        return conList;
    }

    //deloitte-zhj 20231011 with sharing start
    public static List<Contact> searchContactWithAccountId(String hospitalId,List<String> awsDataIds) {
        List<Contact> conList = new List<Contact>(
            [
                SELECT Id, AWS_Data_Id__c, Account.Name
                FROM Contact
                WHERE Account.Hospital__c = :hospitalId AND AWS_Data_Id__c IN:awsDataIds
            ]
        );
        return conList;
    }

    public static List<Contact> searchContactNoWithAccountId(List<String> awsDataIds) {
        List<Contact> conList = new List<Contact>(
            [
                SELECT Id, AWS_Data_Id__c, Account.Name
                FROM Contact
                WHERE AWS_Data_Id__c IN:awsDataIds
            ]
        );
        return conList;
    }

    public static List<Contact> searchContactNoPI(String contactName) {
        List<Contact> conList = new List<Contact>(
            [
                select Id,Name,Account.Name,Phone,Email,MobilePhone from Contact where Name like :contactName
            ]
        );
        return conList;
    }
    //deloitte-zhj 20231011 with sharing end


    public static List<Contact> searchContactByAWSIds(List<String> conAWSIds) {
        List<Contact> conList = new List<Contact>(
            [
                select Id,Name,Account.Name,Phone,Email,MobilePhone,AWS_Data_Id__c from Contact where AWS_Data_Id__c in :conAWSIds
            ]
        );
        return conList;
    }
}