import Constants from 'expo-constants';
import api from './client';

export const apiCheckPhoneLogin = async (body: { phone: string }) => {
   const response = await api.post('/auth/login', body)
   return response.data;
}

export const apiSendOtp = async (body: { phone: string, otp: number }) => {
   const message = "Desa+\nMasukkan kode ini " + body.otp + " pada aplikasi Desa+ anda. Jangan berikan pada siapapun."
   const res = await fetch(
      `${Constants.expoConfig?.extra?.URL_OTP}/api/wa/send-text`,
      {
         method: 'POST',
         headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${Constants.expoConfig?.extra?.WA_SERVER_TOKEN}`,
         },
         body: JSON.stringify({
            number: body.phone,
            text: message
         })
      }
   );
   return res.status
}

export const apiRegisteredToken = async (data: { user: string, token: string, category?: string }) => {
   const response = await api.post(`/mobile/auth-token`, data)
   return response.data;
};

export const apiUnregisteredToken = async (data: { user: string, token: string, category?: string }) => {
   const response = await api.put(`/mobile/auth-token`, data)
   return response.data;
};

export const apiGetCheckToken = async (data: { user: string, token: string }) => {
   const response = await api.post(`mobile/auth-token/check`, data);
   return response.data;
};

export const apiGetVersion = async () => {
   const response = await api.get(`mobile/version`);
   return response.data;
};
