import { TownDatasourceInf } from "../datasource/town_datasource";
import { State } from "../datasource/api/entities/state";
import { Town } from "../datasource/api/entities/town";
import { TownRepositoryInf } from "../../domain/repository/town_repository";

/**
 * Implementation of the TownRepository interface for production.
 */
export class TownRepositoryProd implements TownRepositoryInf {
  constructor(private datasource: TownDatasourceInf) {}

  /**
   * Retrieves all states.
   * @returns A promise that resolves to an array of State objects.
   */
  async getStates(): Promise<State[]> {
    return this.datasource.getStates();
  }

  /**
   * Registers a new town.
   * @param form - The town data to register.
   * @returns A promise that resolves when the town is registered.
   */
  async registerTown(form: Town): Promise<void> {
    return this.datasource.registerTown(form);
  }

  /**
   * Retrieves towns by state.
   * @param idState - The ID of the state.
   * @param stateName - The name of the state.
   * @returns A promise that resolves to an array of Town objects.
   */
  async getTownsByState(idState: number, stateName: string): Promise<Town[]> {
    return this.datasource.getTownsByState(idState, stateName);
  }

  /**
   * Retrieves a town by its ID.
   * @param idTown - The ID of the town.
   * @returns A promise that resolves to a Town object.
   */
  async getTown(idTown: number): Promise<Town> {
    return this.datasource.getTown(idTown);
  }

  /**
   * Updates an existing town.
   * @param form - The town data to update.
   * @returns A promise that resolves when the town is updated.
   */
  async updateTown(form: Town): Promise<void> {
    return this.datasource.updateTown(form);
  }
}
