import { createApi, fakeBaseQuery } from '@reduxjs/toolkit/query/react'; import { PartnerProfile } from '@app-types/index'; // Mock responses const mockSendOtpResponse = { requestId: 'req_mock_001' }; const mockVerifyOtpResponse = { token: 'mock_token_xyz', partnerId: 'partner_001' }; const mockProfile: PartnerProfile = { partnerId: 'partner_001', fullName: 'Rahul Kumar', email: 'rahul@example.com', phone: '9876543210', locationType: 'home', location: { coordinates: { latitude: 12.9716, longitude: 77.5946 }, address: 'Koramangala 4th Block', city: 'Bengaluru', state: 'Karnataka', pincode: '560034', }, avatarUri: null, rating: 4.8, totalDeliveries: 342, acceptanceRate: 95, completionRate: 98, isVerified: true, }; export const authApi = createApi({ reducerPath: 'authApi', baseQuery: fakeBaseQuery(), endpoints: (builder) => ({ sendOtp: builder.mutation<{ requestId: string }, { phone: string }>({ queryFn: async ({ phone: _phone }) => { await new Promise((r) => setTimeout(r, 1000)); return { data: mockSendOtpResponse }; }, }), verifyOtp: builder.mutation< { token: string; partnerId: string }, { requestId: string; otp: string } >({ queryFn: async ({ otp }) => { await new Promise((r) => setTimeout(r, 1000)); if (otp === '000000') { return { error: { status: 'CUSTOM_ERROR', error: 'Invalid OTP' } }; } return { data: mockVerifyOtpResponse }; }, }), getProfile: builder.query({ queryFn: async (_partnerId) => { await new Promise((r) => setTimeout(r, 500)); return { data: mockProfile }; }, }), updateProfile: builder.mutation< PartnerProfile, Partial >({ queryFn: async (updates) => { await new Promise((r) => setTimeout(r, 800)); return { data: { ...mockProfile, ...updates } }; }, }), }), }); export const { useSendOtpMutation, useVerifyOtpMutation, useGetProfileQuery, useUpdateProfileMutation, } = authApi;