import { faker } from '@faker-js/faker'
import { OrganizationKind } from '../../models/kinds.js'
import { nanoid } from '../../nanoid.js'
import type { IOrganization } from '../../models/store/Organization.js'

export class Organization {
  /**
   * Generates a random organization object.
   * @param init Optional values to be present in the object.
   * @returns Random organization
   */
  organization(init: Partial<IOrganization> = {}): IOrganization {
    const {
      key = nanoid(),
      name = faker.company.name(),
      createdBy = nanoid(),
      createdDate = faker.date.past().getTime(),
      grantType = faker.helpers.arrayElement(['owner', 'manager', 'editor', 'viewer'] as const),
    } = init
    return {
      kind: OrganizationKind,
      key,
      name,
      createdBy,
      createdDate,
      grantType,
    }
  }

  /**
   * Generates a list of random organization objects.
   * @param size Number of organizations to generate. Default is 25.
   * @returns List of random organizations
   */
  organizations(size = 25): IOrganization[] {
    const result = []
    for (let i = 0; i < size; i++) {
      result.push(this.organization())
    }
    return result
  }
}
