/**
 * Copyright IBM Corp. 2024, 2025
 */

import { Environment as EnvironmentKind } from '@apic/api-model/test/Environment.js';
import { EnvironmentSchema } from '../schemas/environment.schema.js';
import { transformZodErrors } from '../helpers/zod-error-formatter.helper.js';

export type Environment = EnvironmentKind;

export class EnvironmentFactory {
  create(raw: any): Environment {
    let parsed;
    try {
      parsed = EnvironmentSchema.parse(raw);
    } catch (error) {
      throw transformZodErrors(error);
    }
    const environmentModel = {
      kind: parsed.kind,
      metadata: parsed.metadata,
      spec: parsed.spec,
    };
    return environmentModel;
  }
}
