
import 'package:dio/dio.dart';
import 'package:farmer_client/utils/Request.dart';
import 'package:fluttertoast/fluttertoast.dart';

/**
 * 地址列表
 * @param {*} data
 * @returns
 */
Future getAddress() async {
  return request('/address',
      options: Options(method: 'GET')).catchError((error) => {
    Fluttertoast.showToast(msg: error.error['message']),
  });
}


/**
 * 地址保存
 * @param {*} data
 * @returns
 */
Future addressSave(String address) async {
  return request('/address',
      options: Options(method: 'POST'), data: {'address': address})
      .catchError((error) => {
    Fluttertoast.showToast(msg: error.error['message']),
  });
}



/**
 * 地址删除
 * @param {*} data
 * @returns
 */
Future addressDelete(String id)async{
  return request('/address/$id',options: Options(method: 'DELETE')).catchError((error) =>
  { Fluttertoast.showToast(
      msg: error.error['message']
  ),});

}


/**
 * 地址修改更新
 * @param {*} data
 * @returns
 */
Future addressUpdate(String id,String address)async{
  return request('/address/$id',options: Options(method: 'PUT'),data: {'address':address}).catchError((error) =>
  { Fluttertoast.showToast(
      msg: error.error['message']
  ),});

}


/**
 * 地址是否默认
 * @param {*} data
 * @returns
 */
Future addressDefault(String id)async{
  return request('/address/$id/default',options: Options(method: 'PUT')).catchError((error) =>
  { Fluttertoast.showToast(
      msg: error.error['message']
  ),});

}
