<?php

class TouristAttractionApi extends Api {

  public $apiName = 'touristattraction';

	public function __construct($requestUri, $encryption=true) {
		$encryption = false; // We do not need encryption for this class
		parent::__construct($requestUri, $encryption);
		//$this->encryption = $encryption;
  }

  /**
	 * @OA\Get(
	 *   path="/SAVVY/touristattraction/api/touristattraction?city={city}&country={country}",
	 *   security={{"token": {}}},
	 *   summary="Get geofenceareacity by city and country code",
	 *   @OA\Response(
	 *     response="200",
	 *     description="Found geofence area city",
	 *     @OA\JsonContent(
	 *       type="object"
	 *     )
	 *   )
	 * )
	 */
	public function indexAction() {
		$message = 'No locations found';

    $city = $this->requestParams['city'] ?? '';
    $results = [];
    $res_status = 404;

		try {
      if (empty($city)) {
				throw new Exception("Invalid city");
			}

			$db = new Db();
      list($results, $err) = TouristAttractionModel::get( $db->getConnect(), $city );
      if (!empty($err)) {
        $result = [
          "city_id" => $city,
          "locations" => NULL,
          "error" => $err
        ];
      } else {
        $result = [
          "locations" => $results,
        ];
        $res_status = 200;
      }
		} catch (Exception $e) {
      $message = $e->getMessage();
      $result = [
				"locations" => NULL,
        "error" => $message
      ];
    }

		return $this->response($result, $res_status);
  }
  
  public function viewAction() {}

  public function createAction() {}

  public function updateAction() {}

  public function deleteAction() {}
}


