/**
 * Tests for transformer utils
 */
import {
  transformChannelPayload,
  getTemplateDiffState
} from "../transformerUtils";
import {
  SMS,
  EMAIL,
  MOBILE_PUSH,
  WHATSAPP,
  PUSH,
  ZALO,
  RCS,
  LINE,
  VIBER,
  WEBPUSH,
} from "../../v2Containers/CreativesContainer/constants";

describe("transformerUtils", () => {
  describe("transformChannelPayload", () => {
    it("should return original data for unsupported channel", () => {
      const mockData = {
        channel: "UNSUPPORTED_CHANNEL",
        messageBody: "test message",
      };

      const result = transformChannelPayload(mockData);

      expect(result).toEqual(mockData);
    });

    it("should handle null/undefined channel gracefully", () => {
      const mockData = { messageBody: "test message" };

      const result = transformChannelPayload(mockData);

      expect(result).toEqual(mockData);
    });

    it("should handle case-insensitive channel names", () => {
      const mockData = {
        channel: "sms",
        messageBody: "test message",
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.channel).toEqual(SMS);
    });
  });

  describe("SMS payload transformation", () => {
    it("should transform SMS data correctly with minimal data", () => {
      const mockData = {
        channel: SMS,
        messageBody: "test message",
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(SMS);
      expect(result.centralCommsPayload.smsMessageContent.message).toEqual(
        "test message"
      );
      expect(result.centralCommsPayload.clientName).toEqual("EMF");
    });

    it("should transform SMS data with all options", () => {
      const mockData = {
        channel: SMS,
        messageBody: "test message",
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            smsDeliverySettings: {
              sendDate: "2023-01-01",
            },
          },
        },
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");
      expect(result.centralCommsPayload.smsDeliverySettings).toEqual({
        sendDate: "2023-01-01",
      });
    });

    it("should handle undefined smsData.messageBody", () => {
      const mockData = {
        channel: SMS,
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.smsMessageContent.message).toEqual("");
    });

    it("should handle undefined smsDeliverySettings", () => {
      const mockData = {
        channel: SMS,
        messageBody: "test message",
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {},
        },
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.smsDeliverySettings).toEqual({});
    });

    it("should preserve all original SMS data properties", () => {
      const mockData = {
        channel: SMS,
        messageBody: "test message",
        customField1: "custom value 1",
        customField2: "custom value 2",
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.smsMessageContent.customField1).toEqual(
        "custom value 1"
      );
      expect(result.centralCommsPayload.smsMessageContent.customField2).toEqual(
        "custom value 2"
      );
    });
  });

  describe("Email payload transformation", () => {
    it("should transform Email data correctly with minimal data", () => {
      const mockData = {
        channel: EMAIL,
        emailBody: "<p>test email body</p>",
        emailSubject: "test subject",
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(EMAIL);
      expect(
        result.centralCommsPayload.emailMessageContent.messageBody
      ).toEqual("<p>test email body</p>");
      expect(
        result.centralCommsPayload.emailMessageContent.messageSubject
      ).toEqual("test subject");
      expect(result.centralCommsPayload.clientName).toEqual("EMF");
    });

    it("should transform Email data with all options", () => {
      const mockData = {
        channel: EMAIL,
        emailBody: "<p>test email body</p>",
        emailSubject: "test subject",
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            emailDeliverySettings: {
              sendDate: "2023-01-01",
              senderAddress: "test@example.com",
            },
          },
        },
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");
      expect(result.centralCommsPayload.emailDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        senderAddress: "test@example.com"
      });
    });

    it("should handle undefined email content", () => {
      const mockData = {
        channel: EMAIL
      };

      const result = transformChannelPayload(mockData);

      expect(
        result.centralCommsPayload.emailMessageContent.messageBody
      ).toEqual("");
      expect(
        result.centralCommsPayload.emailMessageContent.messageSubject
      ).toEqual("");
    });

    it("should handle undefined emailDeliverySettings", () => {
      const mockData = {
        channel: EMAIL,
        emailBody: "<p>test email body</p>",
        emailSubject: "test subject"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.emailDeliverySettings).toEqual({});
    });

    it("should preserve all original Email data properties", () => {
      const mockData = {
        channel: EMAIL,
        emailBody: "<p>test email body</p>",
        emailSubject: "test subject",
        customField1: "custom value 1",
        customField2: "custom value 2"
      };

      const result = transformChannelPayload(mockData);

      expect(
        result.centralCommsPayload.emailMessageContent.customField1
      ).toEqual("custom value 1");
      expect(
        result.centralCommsPayload.emailMessageContent.customField2
      ).toEqual("custom value 2");
    });
  });

  describe("Mobile Push payload transformation", () => {
    it("should transform Mobile Push data correctly with minimal data", () => {
      const mockData = {
        channel: MOBILE_PUSH,
        messageSubject: "test push notification"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(PUSH);
      expect(
        result.centralCommsPayload.mpushMessageContent.messageSubject
      ).toEqual("test push notification");
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform Mobile Push data with all options", () => {
      const mockData = {
        channel: MOBILE_PUSH,
        messageSubject: "test push notification",
        accountId: 12345,
        androidContent: {
          title: "Android Title",
          message: "Android Message",
          type: "TEXT",
          cta: {
            actionLink: "https://example.com/android"
          },
          expandableDetails: {
            message: "Expanded Android Message",
            style: "CUSTOM_STYLE",
            ctas: [{ title: "Action 1" }],
            image: "image-url.jpg",
            categoryId: "cat-123"
          },
          custom: {
            prop1: "value1"
          }
        },
        iosContent: {
          title: "iOS Title",
          message: "iOS Message",
          type: "IMAGE",
          cta: {
            actionLink: "https://example.com/ios"
          },
          expandableDetails: {
            message: "Expanded iOS Message",
            style: "CUSTOM_IOS_STYLE",
            ctas: [{ title: "iOS Action 1" }],
            image: "ios-image-url.jpg",
            categoryId: "cat-456"
          },
          custom: {
            prop2: "value2"
          }
        }
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            mobilePushDeliverySettings: {
              sendDate: "2023-01-01"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check Android content
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.title
      ).toEqual("Android Title");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.message
      ).toEqual("Android Message");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.type
      ).toEqual("TEXT");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.cta
          .actionLink
      ).toEqual("https://example.com/android");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.style
      ).toEqual("CUSTOM_STYLE");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.message
      ).toEqual("Expanded Android Message");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.ctas
      ).toEqual([{ title: "Action 1" }]);
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.image
      ).toEqual("image-url.jpg");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.categoryId
      ).toEqual("cat-123");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .customProperties
      ).toEqual({ prop1: "value1" });

      // Check iOS content
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.title
      ).toEqual("iOS Title");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.message
      ).toEqual("iOS Message");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.type
      ).toEqual("IMAGE");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.cta.actionLink
      ).toEqual("https://example.com/ios");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.style
      ).toEqual("CUSTOM_IOS_STYLE");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.message
      ).toEqual("Expanded iOS Message");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.ctas
      ).toEqual([{ title: "iOS Action 1" }]);
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.image
      ).toEqual("ios-image-url.jpg");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.categoryId
      ).toEqual("cat-456");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .customProperties
      ).toEqual({ prop2: "value2" });

      // Check account ID and delivery settings
      expect(result.centralCommsPayload.mpushMessageContent.accountId).toEqual(
        12345
      );
      expect(result.centralCommsPayload.mpushDeliverySettings).toEqual({
        sendDate: "2023-01-01"
      });
    });

    it("should handle missing Android and iOS content", () => {
      const mockData = {
        channel: MOBILE_PUSH,
        messageSubject: "test push notification"
      };

      const result = transformChannelPayload(mockData);

      // Check default Android values
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.type
      ).toEqual("TEXT");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.deviceType
      ).toEqual("ANDROID");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.cta.type
      ).toEqual("EXTERNAL_URL");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.style
      ).toEqual("BIG_TEXT");

      // Check default iOS values
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.type
      ).toEqual("TEXT");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.deviceType
      ).toEqual("IOS");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.title
      ).toEqual("test push notification");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.message
      ).toEqual("");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.cta.type
      ).toEqual("EXTERNAL_URL");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.style
      ).toEqual("BIG_TEXT");
    });

    it("should handle null Android and iOS CTA and expandableDetails", () => {
      const mockData = {
        channel: MOBILE_PUSH,
        messageSubject: "test push notification",
        androidContent: {},
        iosContent: {}
      };

      const result = transformChannelPayload(mockData);

      // Android content checks
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.cta
      ).toBeDefined();
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent.cta.type
      ).toEqual("EXTERNAL_URL");
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails
      ).toBeDefined();
      expect(
        result.centralCommsPayload.mpushMessageContent.androidContent
          .expandableDetails.style
      ).toEqual("BIG_TEXT");

      // iOS content checks
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.cta
      ).toBeDefined();
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent.cta.type
      ).toEqual("EXTERNAL_URL");
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails
      ).toBeDefined();
      expect(
        result.centralCommsPayload.mpushMessageContent.iosContent
          .expandableDetails.style
      ).toEqual("BIG_TEXT");
    });
  });

  describe("WhatsApp payload transformation", () => {
    it("should transform WhatsApp data correctly with minimal data", () => {
      const mockData = {
        channel: WHATSAPP,
        messageBody: "test whatsapp message"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(WHATSAPP);
      expect(
        result.centralCommsPayload.whatsappMessageContent.messageBody
      ).toEqual("test whatsapp message");
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform WhatsApp data with all options", () => {
      const mockData = {
        channel: WHATSAPP,
        messageBody: "test whatsapp message",
        accountId: 12345,
        templateConfigs: {
          id: "template-123",
          name: "greetings_template",
          template: "https://example.com/template",
          varMapped: {
            name: "John Doe",
            product: "Premium Subscription"
          },
          whatsappMedia: {
            header: "Header Content",
            headerVarMapped: { logo: "company-logo.png" },
            footer: "Footer Content"
          },
          category: "MARKETING",
          language: "en_US",
          buttonType: "QUICK_REPLY",
          buttons: [
            { text: "Yes", type: "REPLY" },
            { text: "No", type: "REPLY" }
          ]
        },
        sourceAccountIdentifier: "whatsapp-account-123"
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            whatsappDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "HIGH"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check WhatsApp-specific content
      expect(
        result.centralCommsPayload.whatsappMessageContent.messageBody
      ).toEqual("test whatsapp message");
      expect(
        result.centralCommsPayload.whatsappMessageContent.accountId
      ).toEqual(12345);
      expect(
        result.centralCommsPayload.whatsappMessageContent
          .sourceAccountIdentifier
      ).toEqual("whatsapp-account-123");

      // Check template configs
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs.id
      ).toEqual("template-123");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs.name
      ).toEqual("greetings_template");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .template
      ).toEqual("https://example.com/template");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .varMapped
      ).toEqual({
        name: "John Doe",
        product: "Premium Subscription"
      });
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .whatsappMedia
      ).toEqual({
        header: "Header Content",
        headerVarMapped: { logo: "company-logo.png" },
        footer: "Footer Content"
      });
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .category
      ).toEqual("MARKETING");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .language
      ).toEqual("en_US");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .buttonType
      ).toEqual("QUICK_REPLY");
      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
          .buttons
      ).toEqual([
        { text: "Yes", type: "REPLY" },
        { text: "No", type: "REPLY" }
      ]);

      // Check delivery settings
      expect(result.centralCommsPayload.whatsappDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "HIGH"
      });
    });

    it("should handle missing template configs", () => {
      const mockData = {
        channel: WHATSAPP,
        messageBody: "test whatsapp message"
      };

      const result = transformChannelPayload(mockData);

      expect(
        result.centralCommsPayload.whatsappMessageContent.templateConfigs
      ).toEqual({});
    });

    it("should handle undefined whatsappDeliverySettings", () => {
      const mockData = {
        channel: WHATSAPP,
        messageBody: "test whatsapp message"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.whatsappDeliverySettings).toEqual({});
    });
  });

  describe("Zalo payload transformation", () => {
    it("should transform Zalo data correctly with minimal data", () => {
      const mockData = {
        channel: ZALO,
        messageBody: "test zalo message"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(ZALO);
      expect(result.centralCommsPayload.zaloMessageContent.messageBody).toEqual(
        "test zalo message"
      );
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform Zalo data with all options", () => {
      const mockData = {
        channel: ZALO,
        messageBody: "test zalo message",
        accountId: "zalo-account-123",
        accountName: "Zalo Official Account",
        token: "zalo-auth-token-xyz",
        templateConfigs: {
          id: "template-456",
          name: "promotion_template",
          template: "https://example.com/zalo-template",
          varMapped: {
            customer: "Jane Smith",
            offer: "Summer Sale",
            discount: "25%"
          }
        }
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            zaloDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "NORMAL"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check Zalo-specific content
      expect(result.centralCommsPayload.zaloMessageContent.messageBody).toEqual(
        "test zalo message"
      );
      expect(result.centralCommsPayload.zaloMessageContent.accountId).toEqual(
        "zalo-account-123"
      );
      expect(result.centralCommsPayload.zaloMessageContent.accountName).toEqual(
        "Zalo Official Account"
      );
      expect(result.centralCommsPayload.zaloMessageContent.token).toEqual(
        "zalo-auth-token-xyz"
      );

      // Check template configs
      expect(
        result.centralCommsPayload.zaloMessageContent.templateConfigs.id
      ).toEqual("template-456");
      expect(
        result.centralCommsPayload.zaloMessageContent.templateConfigs.name
      ).toEqual("promotion_template");
      expect(
        result.centralCommsPayload.zaloMessageContent.templateConfigs.template
      ).toEqual("https://example.com/zalo-template");
      expect(
        result.centralCommsPayload.zaloMessageContent.templateConfigs.varMapped
      ).toEqual({
        customer: "Jane Smith",
        offer: "Summer Sale",
        discount: "25%"
      });

      // Check delivery settings
      expect(result.centralCommsPayload.zaloDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "NORMAL"
      });
    });

    it("should handle missing template configs", () => {
      const mockData = {
        channel: ZALO,
        messageBody: "test zalo message"
      };

      const result = transformChannelPayload(mockData);

      expect(
        result.centralCommsPayload.zaloMessageContent.templateConfigs
      ).toEqual({});
    });

    it("should handle undefined zaloDeliverySettings", () => {
      const mockData = {
        channel: ZALO,
        messageBody: "test zalo message"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.zaloDeliverySettings).toEqual({});
    });

    it("should initialize default values when fields are missing", () => {
      const mockData = {
        channel: ZALO
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.zaloMessageContent.messageBody).toEqual(
        ""
      );
      expect(result.centralCommsPayload.zaloMessageContent.accountId).toEqual(
        ""
      );
      expect(result.centralCommsPayload.zaloMessageContent.accountName).toEqual(
        ""
      );
      expect(result.centralCommsPayload.zaloMessageContent.token).toEqual("");
    });
  });

  describe("RCS payload transformation", () => {
    it("should transform RCS data with all options", () => {
      const mockData = {
        channel: RCS,
        messageBody: "test rcs message",
        accountId: "rcs-account-123",
        accountName: "RCS Official Account",
        templateConfigs: {
          id: "template-789",
          name: "notification_template",
          template: "https://example.com/rcs-template",
          varMapped: {
            customer: "Mike Johnson",
            notification: "Important Update",
            urgency: "HIGH"
          }
        }
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            rcsDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "URGENT"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");
      // Check RCS-specific content
      expect(result.centralCommsPayload.rcsMessageContent.messageBody).toEqual(
        "test rcs message"
      );
      expect(result.centralCommsPayload.rcsMessageContent.accountId).toEqual(
        "rcs-account-123"
      );
      expect(result.centralCommsPayload.rcsMessageContent.accountName).toEqual(
        "RCS Official Account"
      );
      // Check template configs
      expect(
        result.centralCommsPayload.rcsMessageContent.templateConfigs.id
      ).toEqual("template-789");
      expect(
        result.centralCommsPayload.rcsMessageContent.templateConfigs.name
      ).toEqual("notification_template");
      expect(
        result.centralCommsPayload.rcsMessageContent.templateConfigs.template
      ).toEqual("https://example.com/rcs-template");
      expect(
        result.centralCommsPayload.rcsMessageContent.templateConfigs.varMapped
      ).toEqual({
        customer: "Mike Johnson",
        notification: "Important Update",
        urgency: "HIGH"
      });
      // Check delivery settings
      expect(result.centralCommsPayload.rcsDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "URGENT"
      });
    });

    it("should handle missing template configs", () => {
      const mockData = {
        channel: RCS,
        messageBody: "test rcs message"
      };

      const result = transformChannelPayload(mockData);

      expect(
        result.centralCommsPayload.rcsMessageContent.templateConfigs
      ).toEqual({});
    });

    it("should handle undefined rcsDeliverySettings", () => {
      const mockData = {
        channel: RCS,
        messageBody: "test rcs message"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.rcsDeliverySettings).toEqual({});
    });

    it("should initialize default values when fields are missing", () => {
      const mockData = {
        channel: RCS
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.rcsMessageContent.messageBody).toEqual(
        ""
      );
      expect(result.centralCommsPayload.rcsMessageContent.accountId).toEqual(
        ""
      );
      expect(result.centralCommsPayload.rcsMessageContent.accountName).toEqual(
        ""
      );
    });
  });

  describe("LINE payload transformation", () => {
    it("should transform LINE data correctly with minimal data", () => {
      const mockData = {
        channel: LINE,
        messageBody: "test line message"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(LINE);
      expect(result.centralCommsPayload.lineMessageContent.messageBody).toEqual(
        "test line message"
      );
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform LINE data with all options", () => {
      const mockData = {
        channel: LINE,
        messageBody: "test line message",
        accountId: 12345,
        accountDetails: "LINE Official Account Details"
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            lineDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "NORMAL"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check LINE-specific content
      expect(result.centralCommsPayload.lineMessageContent.messageBody).toEqual(
        "test line message"
      );
      expect(result.centralCommsPayload.lineMessageContent.accountId).toEqual(12345);
      expect(result.centralCommsPayload.lineMessageContent.accountDetails).toEqual(
        "LINE Official Account Details"
      );

      // Check delivery settings
      expect(result.centralCommsPayload.lineDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "NORMAL"
      });
    });

    it("should handle undefined lineDeliverySettings", () => {
      const mockData = {
        channel: LINE,
        messageBody: "test line message"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.lineDeliverySettings).toEqual({});
    });

    it("should initialize default values when fields are missing", () => {
      const mockData = {
        channel: LINE
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.lineMessageContent.messageBody).toEqual(
        ""
      );
      expect(result.centralCommsPayload.lineMessageContent.accountId).toEqual(0);
      expect(result.centralCommsPayload.lineMessageContent.accountDetails).toEqual(
        ""
      );
    });

    it("should preserve all original LINE data properties", () => {
      const mockData = {
        channel: LINE,
        messageBody: "test line message",
        accountId: 12345,
        accountDetails: "LINE Official Account Details",
        customField1: "custom value 1",
        customField2: "custom value 2"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.lineMessageContent.customField1).toEqual(
        "custom value 1"
      );
      expect(result.centralCommsPayload.lineMessageContent.customField2).toEqual(
        "custom value 2"
      );
    });
  });

  describe("VIBER payload transformation", () => {
    it("should transform VIBER data correctly with minimal data", () => {
      const mockData = {
        channel: VIBER,
        messageBody: "test viber message"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(VIBER);
      expect(result.centralCommsPayload.viberMessageContent.messageBody).toEqual(
        "test viber message"
      );
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform VIBER data with all options", () => {
      const mockData = {
        channel: VIBER,
        messageBody: "test viber message",
        accountId: 67890,
        accountDetails: "VIBER Official Account Details"
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            viberDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "HIGH"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check VIBER-specific content
      expect(result.centralCommsPayload.viberMessageContent.messageBody).toEqual(
        "test viber message"
      );
      expect(result.centralCommsPayload.viberMessageContent.accountId).toEqual(67890);
      expect(result.centralCommsPayload.viberMessageContent.accountDetails).toEqual(
        "VIBER Official Account Details"
      );

      // Check delivery settings
      expect(result.centralCommsPayload.viberDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "HIGH"
      });
    });

    it("should handle undefined viberDeliverySettings", () => {
      const mockData = {
        channel: VIBER,
        messageBody: "test viber message"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.viberDeliverySettings).toEqual({});
    });

    it("should initialize default values when fields are missing", () => {
      const mockData = {
        channel: VIBER
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.viberMessageContent.messageBody).toEqual(
        ""
      );
      expect(result.centralCommsPayload.viberMessageContent.accountId).toEqual(0);
      expect(result.centralCommsPayload.viberMessageContent.accountDetails).toEqual(
        ""
      );
    });

    it("should preserve all original VIBER data properties", () => {
      const mockData = {
        channel: VIBER,
        messageBody: "test viber message",
        accountId: 67890,
        accountDetails: "VIBER Official Account Details",
        customField1: "custom value 1",
        customField2: "custom value 2"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.viberMessageContent.customField1).toEqual(
        "custom value 1"
      );
      expect(result.centralCommsPayload.viberMessageContent.customField2).toEqual(
        "custom value 2"
      );
    });
  });

  describe("WebPush payload transformation", () => {
    it("should transform WebPush data correctly with minimal data", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test webpush notification"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload).toBeDefined();
      expect(result.centralCommsPayload.channel).toEqual(WEBPUSH);
      expect(result.centralCommsPayload.webpushMessageContent.messageSubject).toEqual(
        "test webpush notification"
      );
      expect(result.centralCommsPayload.clientName).toEqual("VENENO");
    });

    it("should transform WebPush data with all options", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test webpush notification",
        messageContent: {
          content: {
            accountId: 12345,
            content: {
              title: "WebPush Title",
              message: "WebPush Message",
              iconImageUrl: "https://example.com/icon.png",
              cta: {
                actionLink: "https://example.com/action",
                actionText: "Click Here"
              },
              expandableDetails: {
                style: "BIG_TEXT",
                message: "Expanded Message"
              }
            },
            offers: [
              { id: "offer-1", title: "Offer 1" },
              { id: "offer-2", title: "Offer 2" }
            ]
          }
        }
      };

      const options = {
        loyaltyMetaData: {
          actionId: "action-123",
          ouId: 456,
          clientName: "TestClient",
          module: "TestModule",
          transformedMessageDetails: {
            webpushDeliverySettings: {
              sendDate: "2023-01-01",
              priority: "HIGH"
            }
          }
        }
      };

      const result = transformChannelPayload(mockData, options);

      // Check base payload
      expect(result.centralCommsPayload.sourceEntityId).toEqual("action-123");
      expect(result.centralCommsPayload.ouId).toEqual(456);
      expect(result.centralCommsPayload.clientName).toEqual("TestClient");
      expect(result.centralCommsPayload.module).toEqual("TestModule");

      // Check WebPush-specific content
      expect(result.centralCommsPayload.webpushMessageContent.channel).toEqual(WEBPUSH);
      expect(result.centralCommsPayload.webpushMessageContent.accountId).toEqual(12345);
      expect(result.centralCommsPayload.webpushMessageContent.messageSubject).toEqual(
        "test webpush notification"
      );
      expect(result.centralCommsPayload.webpushMessageContent.content.title).toEqual(
        "WebPush Title"
      );
      expect(result.centralCommsPayload.webpushMessageContent.content.message).toEqual(
        "WebPush Message"
      );
      expect(result.centralCommsPayload.webpushMessageContent.content.iconImageUrl).toEqual(
        "https://example.com/icon.png"
      );
      expect(result.centralCommsPayload.webpushMessageContent.content.cta).toEqual({
        actionLink: "https://example.com/action",
        actionText: "Click Here"
      });
      expect(result.centralCommsPayload.webpushMessageContent.content.expandableDetails).toEqual({
        style: "BIG_TEXT",
        message: "Expanded Message"
      });
      expect(result.centralCommsPayload.webpushMessageContent.offers).toEqual([
        { id: "offer-1", title: "Offer 1" },
        { id: "offer-2", title: "Offer 2" }
      ]);

      // Check delivery settings
      expect(result.centralCommsPayload.webpushDeliverySettings).toEqual({
        sendDate: "2023-01-01",
        priority: "HIGH"
      });
    });

    it("should handle missing messageContent structure", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test webpush notification"
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.webpushMessageContent.accountId).toEqual(0);
      expect(result.centralCommsPayload.webpushMessageContent.content.title).toEqual("");
      expect(result.centralCommsPayload.webpushMessageContent.content.message).toEqual("");
      expect(result.centralCommsPayload.webpushMessageContent.offers).toEqual([]);
    });

    it("should handle missing content properties", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test webpush notification",
        messageContent: {
          content: {
            accountId: 12345,
            content: {}
          }
        }
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.webpushMessageContent.accountId).toEqual(12345);
      expect(result.centralCommsPayload.webpushMessageContent.content.title).toEqual("");
      expect(result.centralCommsPayload.webpushMessageContent.content.message).toEqual("");
      expect(result.centralCommsPayload.webpushMessageContent.content.iconImageUrl).toBeUndefined();
      expect(result.centralCommsPayload.webpushMessageContent.content.cta).toBeUndefined();
      expect(result.centralCommsPayload.webpushMessageContent.content.expandableDetails).toBeUndefined();
    });

    it("should conditionally include iconImageUrl only when present", () => {
      const mockDataWithoutIcon = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message"
            }
          }
        }
      };

      const resultWithoutIcon = transformChannelPayload(mockDataWithoutIcon);
      expect(resultWithoutIcon.centralCommsPayload.webpushMessageContent.content.iconImageUrl).toBeUndefined();

      const mockDataWithIcon = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message",
              iconImageUrl: "https://example.com/icon.png"
            }
          }
        }
      };

      const resultWithIcon = transformChannelPayload(mockDataWithIcon);
      expect(resultWithIcon.centralCommsPayload.webpushMessageContent.content.iconImageUrl).toEqual(
        "https://example.com/icon.png"
      );
    });

    it("should conditionally include cta only when present", () => {
      const mockDataWithoutCta = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message"
            }
          }
        }
      };

      const resultWithoutCta = transformChannelPayload(mockDataWithoutCta);
      expect(resultWithoutCta.centralCommsPayload.webpushMessageContent.content.cta).toBeUndefined();

      const mockDataWithCta = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message",
              cta: {
                actionLink: "https://example.com",
                actionText: "Click"
              }
            }
          }
        }
      };

      const resultWithCta = transformChannelPayload(mockDataWithCta);
      expect(resultWithCta.centralCommsPayload.webpushMessageContent.content.cta).toEqual({
        actionLink: "https://example.com",
        actionText: "Click"
      });
    });

    it("should conditionally include expandableDetails only when present", () => {
      const mockDataWithoutExpandable = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message"
            }
          }
        }
      };

      const resultWithoutExpandable = transformChannelPayload(mockDataWithoutExpandable);
      expect(resultWithoutExpandable.centralCommsPayload.webpushMessageContent.content.expandableDetails).toBeUndefined();

      const mockDataWithExpandable = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message",
              expandableDetails: {
                style: "BIG_TEXT",
                message: "Expanded"
              }
            }
          }
        }
      };

      const resultWithExpandable = transformChannelPayload(mockDataWithExpandable);
      expect(resultWithExpandable.centralCommsPayload.webpushMessageContent.content.expandableDetails).toEqual({
        style: "BIG_TEXT",
        message: "Expanded"
      });
    });

    it("should handle undefined webpushDeliverySettings", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test webpush notification"
      };

      const options = {
        loyaltyMetaData: {
          transformedMessageDetails: {}
        }
      };

      const result = transformChannelPayload(mockData, options);

      expect(result.centralCommsPayload.webpushDeliverySettings).toEqual({});
    });

    it("should handle empty offers array", () => {
      const mockData = {
        channel: WEBPUSH,
        messageSubject: "test",
        messageContent: {
          content: {
            content: {
              title: "Title",
              message: "Message"
            },
            offers: []
          }
        }
      };

      const result = transformChannelPayload(mockData);

      expect(result.centralCommsPayload.webpushMessageContent.offers).toEqual([]);
    });
  });

  describe("getTemplateDiffState", () => {
    it("should return false for unsupported channel", () => {
      const result = getTemplateDiffState("UNSUPPORTED_CHANNEL", {}, {});

      expect(result).toBe(false);
    });

    it("should handle case-insensitive channel names", () => {
      // Mock implementation for testing channelName case sensitivity
      const oldData = {
        transformedMessageDetails: {
          smsMessageContent: {
            message: "old message"
          }
        }
      };

      const newData = {
        messageBody: "new message"
      };

      const result = getTemplateDiffState("sms", oldData, newData);

      expect(result).toBe(true);
    });

    it("should route to correct diff checker for each channel", () => {
      // SMS test
      expect(
        getTemplateDiffState(
          SMS,
          {
            transformedMessageDetails: { smsMessageContent: { message: "a" } }
          },
          { messageBody: "b" }
        )
      ).toBe(true);

      // EMAIL test
      expect(
        getTemplateDiffState(
          EMAIL,
          {
            transformedMessageDetails: {
              emailMessageContent: { messageBody: "a" }
            }
          },
          { emailBody: "b" }
        )
      ).toBe(true);

      // MOBILE_PUSH test
      expect(
        getTemplateDiffState(
          MOBILE_PUSH,
          {
            transformedMessageDetails: {
              mpushMessageContent: { messageSubject: "a" }
            }
          },
          { messageSubject: "b" }
        )
      ).toBe(true);

      // PUSH test (should route to same checker as MOBILE_PUSH)
      expect(
        getTemplateDiffState(
          PUSH,
          {
            transformedMessageDetails: {
              mpushMessageContent: { messageSubject: "a" }
            }
          },
          { messageSubject: "b" }
        )
      ).toBe(true);
    });
  });

  describe("SMS template diff checking", () => {
    it("should detect changes in message content", () => {
      const oldData = {
        transformedMessageDetails: {
          smsMessageContent: {
            message: "old message"
          }
        }
      };

      const newData = {
        messageBody: "new message"
      };

      const result = getTemplateDiffState(SMS, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when message content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          smsMessageContent: {
            message: "same message"
          }
        }
      };

      const newData = {
        messageBody: "same message"
      };

      const result = getTemplateDiffState(SMS, oldData, newData);

      expect(result).toBe(false);
    });

    it("should handle undefined/null values gracefully", () => {
      // Both values undefined
      expect(
        getTemplateDiffState(
          SMS,
          { transformedMessageDetails: { smsMessageContent: {} } },
          {}
        )
      ).toBe(false);

      // Old value undefined, new value defined
      expect(
        getTemplateDiffState(
          SMS,
          { transformedMessageDetails: { smsMessageContent: {} } },
          { messageBody: "new message" }
        )
      ).toBe(true);

      // Old value defined, new value undefined
      expect(
        getTemplateDiffState(
          SMS,
          {
            transformedMessageDetails: {
              smsMessageContent: { message: "old message" }
            }
          },
          {}
        )
      ).toBe(true);

      // Completely missing properties
      expect(getTemplateDiffState(SMS, {}, {})).toBe(false);
    });
  });

  describe("Email template diff checking", () => {
    it("should detect changes in email body", () => {
      const oldData = {
        transformedMessageDetails: {
          emailMessageContent: {
            messageBody: "<p>old body</p>",
            messageSubject: "same subject"
          }
        }
      };

      const newData = {
        emailBody: "<p>new body</p>",
        emailSubject: "same subject"
      };

      const result = getTemplateDiffState(EMAIL, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in email subject", () => {
      const oldData = {
        transformedMessageDetails: {
          emailMessageContent: {
            messageBody: "<p>same body</p>",
            messageSubject: "old subject"
          }
        }
      };

      const newData = {
        emailBody: "<p>same body</p>",
        emailSubject: "new subject"
      };

      const result = getTemplateDiffState(EMAIL, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in both email body and subject", () => {
      const oldData = {
        transformedMessageDetails: {
          emailMessageContent: {
            messageBody: "<p>old body</p>",
            messageSubject: "old subject"
          }
        }
      };

      const newData = {
        emailBody: "<p>new body</p>",
        emailSubject: "new subject"
      };

      const result = getTemplateDiffState(EMAIL, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when email content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          emailMessageContent: {
            messageBody: "<p>same body</p>",
            messageSubject: "same subject"
          }
        }
      };

      const newData = {
        emailBody: "<p>same body</p>",
        emailSubject: "same subject"
      };

      const result = getTemplateDiffState(EMAIL, oldData, newData);

      expect(result).toBe(false);
    });

    it("should handle undefined/null values gracefully", () => {
      // Both values undefined
      expect(
        getTemplateDiffState(
          EMAIL,
          { transformedMessageDetails: { emailMessageContent: {} } },
          {}
        )
      ).toBe(false);

      // Old body undefined, new body defined
      expect(
        getTemplateDiffState(
          EMAIL,
          {
            transformedMessageDetails: {
              emailMessageContent: { messageSubject: "subject" }
            }
          },
          { emailBody: "<p>new body</p>", emailSubject: "subject" }
        )
      ).toBe(true);

      // Old subject undefined, new subject defined
      expect(
        getTemplateDiffState(
          EMAIL,
          {
            transformedMessageDetails: {
              emailMessageContent: { messageBody: "<p>body</p>" }
            }
          },
          { emailBody: "<p>body</p>", emailSubject: "new subject" }
        )
      ).toBe(true);

      // Completely missing properties
      expect(getTemplateDiffState(EMAIL, {}, {})).toBe(false);
    });
  });

  describe("Mobile Push template diff checking", () => {
    it("should detect changes in push notification subject", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "old subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "new subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in Android title", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "old android title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "new android title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in Android message", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "old android message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "new android message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in Android CTA action link", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com/old" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com/new" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in iOS title", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "old ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "new ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in iOS message", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "old ios message",
              cta: { actionLink: "https://example.com" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "new ios message",
          cta: { actionLink: "https://example.com" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in iOS CTA action link", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com/old-ios" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com/new-ios" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when push data remains the same", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "same subject",
            androidContent: {
              title: "same title",
              message: "same message",
              cta: { actionLink: "https://example.com" }
            },
            iosContent: {
              title: "same ios title",
              message: "same ios message",
              cta: { actionLink: "https://example.com/ios" }
            }
          }
        }
      };

      const newData = {
        messageSubject: "same subject",
        androidContent: {
          title: "same title",
          message: "same message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "same ios title",
          message: "same ios message",
          cta: { actionLink: "https://example.com/ios" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(false);
    });

    it("should handle undefined/null Android and iOS content gracefully", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "subject",
            androidContent: null,
            iosContent: null
          }
        }
      };

      const newData = {
        messageSubject: "subject",
        androidContent: {
          title: "title",
          message: "message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "ios title",
          message: "ios message",
          cta: { actionLink: "https://example.com/ios" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });

    it("should handle undefined/null CTA properties gracefully", () => {
      const oldData = {
        transformedMessageDetails: {
          mpushMessageContent: {
            messageSubject: "subject",
            androidContent: {
              title: "title",
              message: "message"
              // No cta property
            },
            iosContent: {
              title: "ios title",
              message: "ios message"
              // No cta property
            }
          }
        }
      };

      const newData = {
        messageSubject: "subject",
        androidContent: {
          title: "title",
          message: "message",
          cta: { actionLink: "https://example.com" }
        },
        iosContent: {
          title: "ios title",
          message: "ios message",
          cta: { actionLink: "https://example.com/ios" }
        }
      };

      const result = getTemplateDiffState(MOBILE_PUSH, oldData, newData);

      expect(result).toBe(true);
    });
  });

  describe("WhatsApp template diff checking", () => {
    it("should detect changes in message content", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "old message"
          }
        }
      };

      const newData = {
        messageBody: "new message"
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect when new templateConfigs exist but old ones do not", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {}
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "template-123",
          name: "greeting_template"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template ID", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "old-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
              whatsappMedia: { header: "header" },
              category: "MARKETING",
              language: "en_US",
              buttonType: "QUICK_REPLY",
              buttons: [{ text: "Yes" }]
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "new-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
          whatsappMedia: { header: "header" },
          category: "MARKETING",
          language: "en_US",
          buttonType: "QUICK_REPLY",
          buttons: [{ text: "Yes" }]
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template name", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "old_template_name",
              template: "same_template_content"
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "new_template_name",
          template: "same_template_content"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template content", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "old_template_content"
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "new_template_content"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in varMapped", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "Old Name", product: "Old Product" }
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "New Name", product: "New Product" }
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in whatsappMedia", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "Same Name" },
              whatsappMedia: {
                header: "Old Header",
                footer: "Old Footer"
              }
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "Same Name" },
          whatsappMedia: {
            header: "New Header",
            footer: "New Footer"
          }
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in category", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              category: "MARKETING"
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          category: "UTILITY"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in language", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              language: "en_US"
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          language: "es_ES"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in buttonType", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              buttonType: "QUICK_REPLY"
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          buttonType: "CALL_TO_ACTION"
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in buttons array", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              buttons: [
                { text: "Yes", type: "REPLY" },
                { text: "No", type: "REPLY" }
              ]
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          buttons: [
            { text: "Yes", type: "REPLY" },
            { text: "No", type: "REPLY" },
            { text: "Maybe", type: "REPLY" }
          ]
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountId", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            accountId: "old-account-123"
          }
        }
      };

      const newData = {
        messageBody: "same message",
        accountId: "new-account-123"
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in sourceAccountIdentifier", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            sourceAccountIdentifier: "old-identifier"
          }
        }
      };

      const newData = {
        messageBody: "same message",
        sourceAccountIdentifier: "new-identifier"
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when WhatsApp content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          whatsappMessageContent: {
            messageBody: "same message",
            accountId: "same-account",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
              category: "MARKETING",
              language: "en_US",
              buttonType: "QUICK_REPLY",
              buttons: [{ text: "Yes" }]
            }
          }
        }
      };

      const newData = {
        messageBody: "same message",
        accountId: "same-account",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
          category: "MARKETING",
          language: "en_US",
          buttonType: "QUICK_REPLY",
          buttons: [{ text: "Yes" }]
        }
      };

      const result = getTemplateDiffState(WHATSAPP, oldData, newData);

      expect(result).toBe(false);
    });
  });

  describe("Zalo template diff checking", () => {
    it("should detect changes in accountId", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "old-account-123",
            token: "same-token"
          }
        }
      };

      const newData = {
        accountId: "new-account-123",
        token: "same-token"
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in token", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "old-token"
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "new-token"
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect when new templateConfigs exist but old ones do not", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {}
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "template-123",
          name: "greeting_template"
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template ID", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {
              id: "old-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" }
            }
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "new-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" }
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template name", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {
              id: "same-template-123",
              name: "old_template_name",
              template: "same_template_content"
            }
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "same-template-123",
          name: "new_template_name",
          template: "same_template_content"
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template content", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "old_template_content"
            }
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "new_template_content"
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in varMapped", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "Old Name", product: "Old Product" }
            }
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "New Name", product: "New Product" }
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when Zalo content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          zaloMessageContent: {
            accountId: "same-account",
            token: "same-token",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" }
            }
          }
        }
      };

      const newData = {
        accountId: "same-account",
        token: "same-token",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" }
        }
      };

      const result = getTemplateDiffState(ZALO, oldData, newData);

      expect(result).toBe(false);
    });

    it("should handle undefined/null values gracefully", () => {
      // Both values undefined
      expect(
        getTemplateDiffState(
          ZALO,
          { transformedMessageDetails: { zaloMessageContent: {} } },
          {}
        )
      ).toBe(false);

      // Old value has no templateConfigs, new value has templateConfigs
      expect(
        getTemplateDiffState(
          ZALO,
          {
            transformedMessageDetails: {
              zaloMessageContent: { accountId: "acc", token: "token" }
            }
          },
          {
            accountId: "acc",
            token: "token",
            templateConfigs: { id: "id", name: "name" }
          }
        )
      ).toBe(true);
    });
  });

  describe("LINE template diff checking", () => {
    it("should detect changes in message content", () => {
      const oldData = {
        transformedMessageDetails: {
          lineMessageContent: {
            messageBody: "old line message",
            accountId: "same-account",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "new line message",
        accountId: "same-account",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(LINE, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountId", () => {
      const oldData = {
        transformedMessageDetails: {
          lineMessageContent: {
            messageBody: "same line message",
            accountId: "old-account-123",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "same line message",
        accountId: "new-account-123",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(LINE, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountDetails", () => {
      const oldData = {
        transformedMessageDetails: {
          lineMessageContent: {
            messageBody: "same line message",
            accountId: "same-account",
            accountDetails: "old-account-details",
          },
        },
      };

      const newData = {
        messageBody: "same line message",
        accountId: "same-account",
        accountDetails: "new-account-details",
      };

      const result = getTemplateDiffState(LINE, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when LINE content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          lineMessageContent: {
            messageBody: "same line message",
            accountId: "same-account",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "same line message",
        accountId: "same-account",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(LINE, oldData, newData);

      expect(result).toBe(false);
    });

    it("should detect actual changes despite type differences", () => {
      const oldData = {
        transformedMessageDetails: {
          lineMessageContent: {
            messageBody: "same message",
            accountId: 12345,
            accountDetails: "same details",
          },
        },
      };

      const newData = {
        messageBody: "same message",
        accountId: "12346",
        accountDetails: "same details",
      };

      // Should return true because "12345" !== "12346"
      const result = getTemplateDiffState(LINE, oldData, newData);

      expect(result).toBe(true);
    });

    it("should handle undefined/null values gracefully", () => {
      // Both values undefined
      expect(
        getTemplateDiffState(
          LINE,
          { transformedMessageDetails: { lineMessageContent: {} } },
          {}
        )
      ).toBe(false);

      // Old value undefined, new value defined
      expect(
        getTemplateDiffState(
          LINE,
          { transformedMessageDetails: { lineMessageContent: {} } },
          { messageBody: "new message" }
        )
      ).toBe(true);

      // Old value defined, new value undefined
      expect(
        getTemplateDiffState(
          LINE,
          {
            transformedMessageDetails: {
              lineMessageContent: { messageBody: "old message" }
            }
          },
          {}
        )
      ).toBe(true);
    });
  });

  describe("VIBER template diff checking", () => {
    it("should detect changes in message content", () => {
      const oldData = {
        transformedMessageDetails: {
          viberMessageContent: {
            messageBody: "old viber message",
            accountId: "same-account",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "new viber message",
        accountId: "same-account",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(VIBER, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountId", () => {
      const oldData = {
        transformedMessageDetails: {
          viberMessageContent: {
            messageBody: "same viber message",
            accountId: "old-account-123",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "same viber message",
        accountId: "new-account-123",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(VIBER, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountDetails", () => {
      const oldData = {
        transformedMessageDetails: {
          viberMessageContent: {
            messageBody: "same viber message",
            accountId: "same-account",
            accountDetails: "old-account-details",
          },
        },
      };

      const newData = {
        messageBody: "same viber message",
        accountId: "same-account",
        accountDetails: "new-account-details",
      };

      const result = getTemplateDiffState(VIBER, oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when VIBER content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          viberMessageContent: {
            messageBody: "same viber message",
            accountId: "same-account",
            accountDetails: "same-details",
          },
        },
      };

      const newData = {
        messageBody: "same viber message",
        accountId: "same-account",
        accountDetails: "same-details",
      };

      const result = getTemplateDiffState(VIBER, oldData, newData);

      expect(result).toBe(false);
    });

    it("should detect actual changes despite type differences", () => {
      const oldData = {
        transformedMessageDetails: {
          viberMessageContent: {
            messageBody: "same message",
            accountId: 67890,
            accountDetails: "same details",
          },
        },
      };

      const newData = {
        messageBody: "same message",
        accountId: "67891",
        accountDetails: "same details",
      };

      // Should return true because "67890" !== "67891"
      const result = getTemplateDiffState(VIBER, oldData, newData);

      expect(result).toBe(true);
    });

    it("should handle undefined/null values gracefully", () => {
      // Both values undefined
      expect(
        getTemplateDiffState(
          VIBER,
          { transformedMessageDetails: { viberMessageContent: {} } },
          {}
        )
      ).toBe(false);

      // Old value undefined, new value defined
      expect(
        getTemplateDiffState(
          VIBER,
          { transformedMessageDetails: { viberMessageContent: {} } },
          { messageBody: "new message" }
        )
      ).toBe(true);

      // Old value defined, new value undefined
      expect(
        getTemplateDiffState(
          VIBER,
          {
            transformedMessageDetails: {
              viberMessageContent: { messageBody: "old message" }
            }
          },
          {}
        )
      ).toBe(true);
    });
  });

  describe("RCS template diff checking", () => {
    it("should detect changes in accountId", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "old-account-123",
            accountName: "same-account-name",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
            },
          },
        },
      };

      const newData = {
        accountId: "new-account-123",
        accountName: "same-account-name",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
        },
      };

      const result = getTemplateDiffState(RCS, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in accountName", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "same-account",
            accountName: "old-account-name",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
            },
          },
        },
      };

      const newData = {
        accountId: "same-account",
        accountName: "new-account-name",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
        },
      };

      const result = getTemplateDiffState(RCS, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in template configs structure", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "same-account",
            accountName: "same-account-name",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              // Missing template and varMapped properties
            },
          },
        },
      };

      const newData = {
        accountId: "same-account",
        accountName: "same-account-name",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
        },
      };

      const result = getTemplateDiffState(RCS, oldData, newData);

      expect(result).toBe(true);
    });

    it("should detect changes in account details", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "old-account-123",
            accountName: "old-account-name",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
            },
          },
        },
      };

      const newData = {
        accountId: "new-account-123",
        accountName: "new-account-name",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
        },
      };

      const result = getTemplateDiffState("RCS", oldData, newData);

      expect(result).toBe(true);
    });

    it("should return false when RCS content is the same", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "same-account",
            accountName: "same-account-name",
            templateConfigs: {
              id: "same-template-123",
              name: "same_template_name",
              template: "same_template_content",
              varMapped: { customer: "John" },
            },
          },
        },
      };

      const newData = {
        accountId: "same-account",
        accountName: "same-account-name",
        templateConfigs: {
          id: "same-template-123",
          name: "same_template_name",
          template: "same_template_content",
          varMapped: { customer: "John" },
        },
      };

      const result = getTemplateDiffState(RCS, oldData, newData);

      expect(result).toBe(false);
    });

    it("should handle missing transformedMessageDetails with default values", () => {
      const oldData = {
        // Missing transformedMessageDetails completely
      };

      const newData = {
        accountId: "new-account",
        accountName: "new-account-name",
        templateConfigs: {
          id: "template-123",
          name: "template_name",
        },
      };

      // This should trigger default value assignments in destructuring
      const result = getTemplateDiffState(RCS, oldData, newData);

      // Should return true because oldData has no rcsMessageContent
      expect(result).toBe(true);
    });

    it("should handle empty newData with default values", () => {
      const oldData = {
        transformedMessageDetails: {
          rcsMessageContent: {
            accountId: "old-account",
            accountName: "old-account-name",
            templateConfigs: {
              id: "template-123",
              name: "template_name",
            },
          },
        },
      };

      const newData = null;

      // This should trigger default value assignments in destructuring for newData
      const result = getTemplateDiffState(RCS, oldData, newData);

      // Should return true because newData is null
      expect(result).toBe(true);
    });
  });
});
