/**
 * @aurora-catalyst-generated
 * @source cliter/iam
 */
import { boundedContexts, permissions } from '@app/iam/iam.seed';
import {
  IAM_BOUNDED_CONTEXT_SEEDER,
  type IIamBoundedContextSeeder,
} from '@bridges/iam/bounded-context/ports';
import { IAM_PERMISSION_SEEDER, type IIamPermissionSeeder } from '@bridges/iam/permission/ports';
import { Inject, Injectable, OnApplicationBootstrap } from '@nestjs/common';

@Injectable()
export class IamSeeder implements OnApplicationBootstrap {
  constructor(
    @Inject(IAM_BOUNDED_CONTEXT_SEEDER)
    private readonly boundedContextSeeder: IIamBoundedContextSeeder,
    @Inject(IAM_PERMISSION_SEEDER)
    private readonly permissionSeeder: IIamPermissionSeeder,
  ) {}

  async onApplicationBootstrap(): Promise<void> {
    await this.boundedContextSeeder.seedAll(boundedContexts, {
      updateOnDuplicate: ['name', 'root', 'sort', 'isActive'],
      conflictAttributes: ['id'],
    });

    void this.permissionSeeder.seedAll(permissions, {
      updateOnDuplicate: ['name', 'boundedContextId'],
      conflictAttributes: ['id'],
    });
  }
}
