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

/**
 * Global Unified Service Mock Factories
 * Refined to match the actual API response mapping (e.g. applicantName, overallStatus).
 */

export const createGlobalMockApplication = (overrides = {}) => ({
  id: GLOBAL_MOCK_IDS.APP_ID,
  applicationId: GLOBAL_MOCK_IDS.REG_ID,
  applicantName: "Global Test Applicant",
  email: TEST_STRINGS.VALID_EMAIL,
  phone: TEST_STRINGS.VALID_PHONE,
  overallStatus: SHARED_APP_STATUSES.SUBMITTED,
  progressPercentage: 50,
  ddLeadShortlisted: true, // Default to true for ApplicationsPage visibility
  isShortlisted: true,
  uploadedDocuments: [],
  workNotes: [],
  reports: [],
  createdAt: new Date().toISOString(),
  ...overrides,
});

export const mockOnboardingService = {
  getApplications: jest.fn().mockResolvedValue({ success: true, data: [] }),
  /** Matches real onboarding.service — returns the application payload, not the HTTP envelope */
  getApplicationById: jest.fn().mockResolvedValue(createGlobalMockApplication()),
  submitStageDecision: jest.fn().mockResolvedValue({ success: true, data: { statusUpdated: true } }),
  updateApplication: jest.fn().mockResolvedValue({ success: true }),
  /** Service unwraps to an array; do not return raw API envelope here */
  getDocuments: jest.fn().mockResolvedValue([]),
  getInterviews: jest.fn().mockResolvedValue([]),
  getSystemConfigs: jest.fn().mockResolvedValue({}),
  /** useApplicationDetailsData sets `deposits` from this; must be an array of { depositType, status } */
  getSecurityDeposit: jest.fn().mockResolvedValue([
    { depositType: "FIRST_FILL", status: "Verified" },
    { depositType: "SECURITY_DEPOSIT", status: "Verified" },
  ]),
  /** ApplicationDetails reads `res.data` from this result */
  getDocumentConfigs: jest.fn().mockResolvedValue({ data: [] }),
  assignArchitectureTeam: jest.fn().mockResolvedValue({ success: true }),
  shortlistApplications: jest.fn().mockResolvedValue({ success: true }),
};

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

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

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