import Api from './api'
import { Platform } from 'react-native'
import Config from 'src/utils/Config'
import DeviceInfo from 'react-native-device-info'

export const getUserProfile = () => {
  return Api.get('/me');
}

export const testConnect = () => {
  return Api.get('/');
}

export const registerDevice = (pushToken) => {
  return Api.post('/register/device', {
    push_token: pushToken,
    uid: DeviceInfo.getUniqueId(),
    brand: DeviceInfo.getBrand(),
    model: DeviceInfo.getModel()
  });
}

export const register = (user) => {
  return Api.post('/register',
    user
  );
}

export const login = (params) => {
  return Api.post('/login',
    params
  );
}

export const dashboard = (params) => {
  return Api.get('/me/dashboard');
}

export const getNews = (params) => {
  return Api.get('/news');
}

export const getNewsPage = (page = 1) => {
  return Api.get('/news?page='+page);
}

export const getNewsDetail = (news_id) => {
  return Api.get('/news/'+news_id);
}

export const getNewsByProject = (project_id) => {
  return Api.get('/news_projects/'+project_id);
}

export const project = (keyword) => {
  return Api.get('/project');
}

export const getBuildingByProjectId = (project_id) => {
  return Api.get(`/project/${project_id}/building`);
}

export const room = (project_id) => {
  return Api.get(`/room/?project_id=${project_id}`);
}

export const roomdetail = (room_id) => {
  return Api.get('/room_detail', {
    room_id: room_id
  });
}

export const payment = (user_id) => {
    return Api.get('/payment', {
        user_id: user_id
    });
}

export const payment_detail = (payments_id) => {
  return Api.get('/payment/'+payments_id);
}

export const total_payment = (user_id) => {
  return Api.get('/payment/' + user_id);
}

export const edit_profile = (user) => {
  const formData = new FormData()
  for (let k in user) {
    formData.append(k, user[k])
  }
  return Api.post('/me/profile', formData );
}

export const get_notification = (user_id, page) => {
  return Api.get('/notification', {
    user_id: user_id,
    page: page
  })
}

export const read_notification = (noti_id) => {
  return Api.post('/notification',{noti_id: noti_id})
}

export const count_notification = (user_id) => {
  return Api.get('/notification/count', {
    user_id: user_id
  })

}

export const getSubscription = (customer_id,type) => {
  return Api.get('/subscription', {
    customer_id: customer_id,
    type: type,
  })
}

export const postSubscription = (customer_id,type) => {
  return Api.post('/subscription', {
    customer_id: customer_id,
    type: type,
  })
}

export const getProductList = () => {
  return Api.get('/product');
}

export const getProductDetail = (product_id) => {
  return Api.get('/product/'+product_id);
}

export const getServices = () => {
  return Api.get('/service');
}

export const getServicesType = (service_id) => {
  return Api.get('/service/type/'+service_id);
}

export const getServicesDetail = (service_id) => {
  return Api.get('/service/'+service_id);
}

export const getRepairList = (service_id) => {
  return Api.get('/repair');
}

export const getRepairById = (repair_id) => {
  return Api.get('/repair/'+repair_id);
}

export const postRepair = (param) => {
  return Api.post('/repair',param)
}

export const postReserveRoom = (room_id,params) => {
  return Api.post(`/room/${room_id}/reserve`, params)
}

//Suggestion
export const postSuggestion = (params) => {
  const formData = new FormData()
  for (let k in params) {
    formData.append(k, params[k])
  }
  return Api.post('/suggestion',formData)
}

export const postSuggestionLogin = (params) => {
  const formData = new FormData()
  for (let k in params) {
    formData.append(k, params[k])
  }
  return Api.post('/service_suggestion',formData)
}


//Question & Answer
export const getConversation = () => {
  return Api.get('/conversation');
}

export const postConversation = (param) => {
  return Api.post('/conversation/messages',param);
}

//Object & Message
export const getObjectMessage = () => {
  return Api.get('/parcel');
}

export const postSignatureImage = (params) => {
  const formData = new FormData()
  for (let k in params) {
    formData.append(k, params[k])
  }
  return Api.post('/parcel',formData);
}

export const getObjectMessageByID = (id) => {
  return Api.get(`/parcel/${id}`);
}

//Meter
export const getMeterList = () => {
  return Api.get('/meter');
}

export const getRoomSlideList = (roon_id) => {
  return Api.get('/meter?room_id='+roon_id);
}

export const postMeter = (params) => {
  const formData = new FormData()
  for (let k in params) {
    formData.append(k, params[k])
  }

  return Api.post('/meter',formData);
}

export const postMeterImage = (params) => {
  const formData = new FormData()
  for (let k in params) {
    formData.append(k, params[k])
  }

  return Api.post('/ocr',formData);
}

export const disconnectFacebook = (user) => {
  return Api.post('/disconnectFacebook',
    user
  );
}
