import axios from "axios";
import { ActivityDataSource } from "../../../domain/datasources/activity_datasource";
import { Languages } from "../../../../lang/translations";
import { ActivityPlaceModel } from "../../models/activity_place_model";
import { activityPlaceModelToEntity } from "../../utils/activity_utils";
import { API_URL } from "../../../../common/const/api";
import { ActivityPlaceEntity } from "../../../domain/entities/activity_place_entity";

export class ActivityDatasourceProd implements ActivityDataSource {
  constructor(private lang: string = Languages.SPANISH) {}
  async rankActivity(activityId: number, rank: number): Promise<void> {
    const { status } = await axios.post(`${API_URL}/visited`, {
      idPlace: activityId,
      rating: rank,
    });
    console.info("rankActivity", status);
    if (status !== 201) {
      throw new Error("Error al calificar la actividad");
    }
  }
  async getPlaceActivity(
    activityId: number,
    townId: number,
    stateId: number,
    placeNumber: number
  ): Promise<ActivityPlaceEntity> {
    const { data, status } = await axios.get<ActivityPlaceModel>(
      `${API_URL}/point/${placeNumber}?lang=${this.lang}`
    );
    if (status !== 200) {
      throw new Error("Error al obtener la información del lugar");
    }
    console.log(data);
    return activityPlaceModelToEntity(data);
  }
}
