const { error, success } = require("../../handlers");
const { NearbyFacility } = require("../../models");
const {
  PropertyTypes,
  PropertyFeature,
  PropertyFurnishing,
  PropertyStatus,
  Reports,
  States,
  PropertyKind,
} = require("../../utils/Constants");
const { getCities } = require("../../utils/GoogleMap");

const index = async (req, res) => {
  try {
    let data = {};
    data["PropertyTypes"] = PropertyTypes;
    data["PropertyKind"] = PropertyKind;
    data["PropertyFeature"] = PropertyFeature;
    data["PropertyFurnishing"] = PropertyFurnishing;
    data["PropertyStatus"] = PropertyStatus;
    data["Reports"] = Reports;
    return success(res, {
      msg: "Common data listed successfully!!",
      data: [data],
    });
  } catch (err) {
    return error(res, {
      msg: "Something went wrong!!",
    });
  }
};

const getCitiesAndStates = async (req, res) => {
  try {
    return success(res, {
      msg: "States and cities listed successfully!!",
      data: States,
    });
  } catch (err) {
    return error(res, {
      msg: "Something went wrong!!",
    });
  }
};

const getNearbyFacilities = async (req, res) => {
  try {
    let facilities = await NearbyFacility.findAll({
      order: [["id", "desc"]],
    });
    return success(res, {
      msg: "NearbyFacilities listed successfully!!",
      data: facilities,
    });
  } catch (err) {
    return error(res, {
      msg: "Something went wrong!!",
    });
  }
};

module.exports = {
  index,
  getCitiesAndStates,
  getNearbyFacilities,
};
