import { AdminDatasourceInf } from "../datasource/admin_datasource";
import {
  Admin,
  AdminFormValues,
} from "../datasource/api/entities/admin_form_values";
import { ResetPasswordValues } from "../datasource/api/entities/reset_password_values";
import { AdminRepositoryInf } from "../../domain/repository/admin_repository";

/**
 * Implementation of the AdminRepository interface for production.
 */
export class AdminRepositoryProd implements AdminRepositoryInf {
  constructor(private datasource: AdminDatasourceInf) {}

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

  /**
   * Retrieves admin information by token.
   * @param token - The token of the admin.
   * @returns A promise that resolves to an Admin object.
   */
  async getAdminInfo(token: string): Promise<Admin> {
    return this.datasource.getAdminInfo(token);
  }

  /**
   * Changes the password of an admin.
   * @param token - The token of the admin.
   * @param prevPassword - The previous password.
   * @param newPassword - The new password.
   * @returns A promise that resolves when the password is changed.
   */
  async changePassword(
    token: string,
    prevPassword: string,
    newPassword: string
  ): Promise<void> {
    return this.datasource.changePassword(token, prevPassword, newPassword);
  }

  /**
   * Retrieves admins by town.
   * @param idTown - The ID of the town.
   * @returns A promise that resolves to an array of Admin objects.
   */
  async getAdminsByTown(idTown: number): Promise<Admin[]> {
    return this.datasource.getAdminsByTown(idTown);
  }

  /**
   * Generates a reset code for the given email.
   * @param email - The email to generate the reset code for.
   * @returns A promise that resolves when the reset code is generated.
   */
  async generateResetCode(email: string): Promise<void> {
    return this.datasource.generateResetCode(email);
  }

  /**
   * Resets the password using the given form values.
   * @param form - The reset password form values.
   * @returns A promise that resolves when the password is reset.
   */
  async resetPassword(form: ResetPasswordValues): Promise<void> {
    return this.datasource.resetPassword(form);
  }
}
