import { Body, Controller, Post, Request, UsePipes, Headers } from "@nestjs/common";
import type { RequestWithUser } from "@bff/modules/auth/auth.types";
import { SimOrderActivationService } from "./sim-order-activation.service";
import { ZodValidationPipe } from "@customer-portal/validation/nestjs";
import {
  simOrderActivationRequestSchema,
  type SimOrderActivationRequest,
} from "@customer-portal/domain/sim";

@Controller("subscriptions/sim/orders")
export class SimOrdersController {
  constructor(private readonly activation: SimOrderActivationService) {}

  @Post("activate")
  @UsePipes(new ZodValidationPipe(simOrderActivationRequestSchema))
  async activate(
    @Request() req: RequestWithUser,
    @Body() body: SimOrderActivationRequest,
    @Headers("x-idempotency-key") idempotencyKey?: string
  ) {
    const result = await this.activation.activate(req.user.id, body, idempotencyKey);
    return result;
  }
}
