/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { asArray } from '../utils/index.js';
import { asUser } from './User.js';
/**
 * Convert the raw user object to {@link IOrganization}.
 *
 * @param org Raw user object from DB
 * @returns Organizatin
 */
export function asOrganization(org) {
    let members = new Array();
    if (org.members) {
        members = asArray(org.members).map(m => {
            const member = asUser(m);
            return member;
        });
    }
    const organization = {
        id: org.uid,
        handle: org.handle_s,
        type: 'organization',
        name: org.name_t,
        description: org.description_t,
        public: org.public_b,
        members,
        teams: [],
        creationDate: new Date(org.creation_ts_dt),
        setMembers(members) {
            this.members = members;
        },
    };
    return organization;
}
