/**
 * @description Tests for DocusignEnvelopeRequestHandler
 * @author Paul Huliganga
 * @date 2026-02-25
 */
@isTest
public class DocusignEnvelopeRequestHandlerTest {
    
    @isTest
    static void testValidateRequest_Success() {
        DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
        req.templateIds = new List<String>{ 'template1', 'template2' };
        req.recordId = '001xx000003DHf';
        
        Test.startTest();
        DocusignEnvelopeRequestHandler.validateRequest(req);
        Test.stopTest();
        
        Assert.isTrue(true, 'Validation should pass');
    }
    
    @isTest
    static void testValidateRequest_NoTemplateIds() {
        DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
        req.templateIds = new List<String>();
        req.recordId = '001xx000003DHf';
        
        try {
            DocusignEnvelopeRequestHandler.validateRequest(req);
            Assert.fail('Should throw IllegalArgumentException');
        } catch (IllegalArgumentException e) {
            Assert.isTrue(e.getMessage().contains('At least one template ID'), 'Correct error');
        }
    }
    
    @isTest
    static void testValidateRequest_TooManyTemplates() {
        DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
        req.templateIds = new List<String>();
        for (Integer i = 0; i < 15; i++) {
            req.templateIds.add('template' + i);
        }
        req.recordId = '001xx000003DHf';
        
        try {
            DocusignEnvelopeRequestHandler.validateRequest(req);
            Assert.fail('Should throw IllegalArgumentException');
        } catch (IllegalArgumentException e) {
            Assert.isTrue(e.getMessage().contains('Maximum 14 templates'), 'Correct error');
        }
    }
    
    @isTest
    static void testValidateRequest_NoRecordId() {
        DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
        req.templateIds = new List<String>{ 'template1' };
        req.recordId = '';
        
        try {
            DocusignEnvelopeRequestHandler.validateRequest(req);
            Assert.fail('Should throw IllegalArgumentException');
        } catch (IllegalArgumentException e) {
            Assert.isTrue(e.getMessage().contains('Salesforce record ID'), 'Correct error');
        }
    }
    
    @isTest
    static void testValidateRequest_BlankTemplateId() {
        DocusignEnvelopeRequest req = new DocusignEnvelopeRequest();
        req.templateIds = new List<String>{ 'template1', '', 'template3' };
        req.recordId = '001xx000003DHf';
        
        try {
            DocusignEnvelopeRequestHandler.validateRequest(req);
            Assert.fail('Should throw IllegalArgumentException');
        } catch (IllegalArgumentException e) {
            Assert.isTrue(e.getMessage().contains('Template ID cannot be blank'), 'Correct error');
        }
    }
}
