import { TEST_STRINGS, GLOBAL_MOCK_IDS, SHARED_APP_STATUSES } from "./constants";

/**
 * Global Unified Service Mock Factories
 * Provides standard, passing responses for all major services.
 */

export const createGlobalMockApplication = (overrides = {}) => ({
  id: GLOBAL_MOCK_IDS.APP_ID,
  registrationNumber: GLOBAL_MOCK_IDS.REG_ID,
  name: "Global Test Applicant",
  email: TEST_STRINGS.VALID_EMAIL,
  phone: TEST_STRINGS.VALID_PHONE,
  status: SHARED_APP_STATUSES.SUBMITTED,
  currentProgress: 50,
  uploadedDocuments: [],
  workNotes: [],
  reports: [],
  ...overrides,
});

export const globalMockOnboardingService = {
  getApplications: jest.fn().mockResolvedValue({ success: true, data: [] }),
  getApplicationById: jest.fn().mockResolvedValue({ success: true, data: createGlobalMockApplication() }),
  submitStageDecision: jest.fn().mockResolvedValue({ success: true, data: { statusUpdated: true } }),
  updateApplication: jest.fn().mockResolvedValue({ success: true }),
  getDocuments: jest.fn().mockResolvedValue({ success: true, data: [] }),
  getSecurityDeposit: jest.fn().mockResolvedValue({ success: true, data: [] }),
  getDocumentConfigs: jest.fn().mockResolvedValue({ success: true, data: [] }),
  assignArchitectureTeam: jest.fn().mockResolvedValue({ success: true }),
  shortlistApplications: jest.fn().mockResolvedValue({ success: true }),
};

export const globalMockCollaborationService = {
  getWorknotes: jest.fn().mockResolvedValue({ success: true, data: [] }),
  addWorknote: jest.fn().mockResolvedValue({ success: true }),
};

export const globalMockEORService = {
  getChecklist: jest.fn().mockResolvedValue({ success: true, data: { items: [] } }),
  updateItem: jest.fn().mockResolvedValue({ success: true }),
};

export const globalMockAdminService = {
  getAllUsers: jest.fn().mockResolvedValue({ success: true, data: [] }),
};

/**
 * Helper to prepare global mocks in any test file.
 */
export const setupUnifiedMocks = () => {
  return {
    onboardingService: globalMockOnboardingService,
    collaborationService: globalMockCollaborationService,
    worknoteService: globalMockCollaborationService,
    eorService: globalMockEORService,
    adminService: globalMockAdminService,
    API: {
      ...globalMockOnboardingService,
      getFddAssignment: jest.fn().mockResolvedValue({ success: true, data: {} }),
      uploadDocument: jest.fn().mockResolvedValue({ success: true }),
      submitFddReport: jest.fn().mockResolvedValue({ success: true }),
      flagNonResponsive: jest.fn().mockResolvedValue({ success: true }),
    },
  };
};
