import { Controller, Post, Body, UseGuards } from "@nestjs/common";
import { PhrRecordService } from "./abhaaddress_userid_mapping.service";
import { SkipThrottle, Throttle, ThrottlerGuard } from "@nestjs/throttler";

@Controller("abha_address_user_id_mapping")
export class PhrRecordController {
  constructor(private readonly phrRecordService: PhrRecordService) { }

  @Post()
  @UseGuards(ThrottlerGuard)
  @SkipThrottle()
  async createRecord(
    @Body("abhaAddress") abhaAddress: string,
    @Body("userId") userId: number | null
  ) {
    if (!abhaAddress) {
      return {
        status: process.env.FAILED_STATUS_ABHA_ADDRESS_MAPPING,
        message: process.env.ABHA_ADDRESS_NOT_FOUND,
      };
    }

    return this.phrRecordService.createRecord(abhaAddress, userId);
  }
}
