/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
/**
 * Project domain model wrapping raw space data with project-specific accessors.
 *
 * @example
 * ```typescript
 * const projects = await client.getProjects();
 * const project = projects[0];
 * console.log(project.hasAgent); // false
 * await client.assignAgent(project.uid, 'my-agent-pod');
 * ```
 */
export class ProjectDTO {
    _data;
    _deleted = false;
    _createdAt;
    constructor(data) {
        this._data = data;
        // Cache creation date at construction to ensure stable value
        this._createdAt = data.creation_ts_dt
            ? new Date(data.creation_ts_dt)
            : new Date();
    }
    /** Unique identifier for the project. */
    get uid() {
        this._checkDeleted();
        return this._data.uid;
    }
    /** Internal numeric/string ID from the backend. Falls back to UID when not present. SDK client methods accept `uid` directly. */
    get id() {
        this._checkDeleted();
        return this._data.id ?? this._data.uid;
    }
    /** URL-friendly handle. */
    get handle() {
        this._checkDeleted();
        return this._data.handle_s;
    }
    /** Project name. */
    get name() {
        this._checkDeleted();
        return this._data.name_t;
    }
    /** Project description. */
    get description() {
        this._checkDeleted();
        return this._data.description_t ?? '';
    }
    /** Space variant (should be 'project'). */
    get variant() {
        this._checkDeleted();
        return this._data.variant_s;
    }
    /** Whether the project is public. */
    get isPublic() {
        this._checkDeleted();
        return this._data.public_b ?? false;
    }
    /** Creation date (stable across calls). */
    get createdAt() {
        this._checkDeleted();
        return this._createdAt;
    }
    /** Attached agent runtime pod name, if any. */
    get attachedAgentPodName() {
        this._checkDeleted();
        return this._data.attached_agent_pod_name_s || undefined;
    }
    /** Attached agent spec ID (e.g., 'data-acquisition'), if any. */
    get attachedAgentSpecId() {
        this._checkDeleted();
        return this._data.attached_agent_spec_id_s || undefined;
    }
    /** Human-readable name of the attached agent runtime, if any. */
    get attachedAgentGivenName() {
        this._checkDeleted();
        return this._data.attached_agent_given_name_s || undefined;
    }
    /** Whether an agent is currently attached to this project. */
    get hasAgent() {
        this._checkDeleted();
        return !!this._data.attached_agent_pod_name_s;
    }
    /** Mark this project as deleted. */
    markDeleted() {
        this._deleted = true;
    }
    /** Whether this project has been deleted. */
    get isDeleted() {
        return this._deleted;
    }
    /**
     * Get project data in camelCase format.
     * @returns Project data with camelCase properties
     */
    toJSON() {
        this._checkDeleted();
        return {
            uid: this.uid,
            id: this.id,
            handle: this.handle,
            name: this.name,
            description: this.description,
            variant: this.variant,
            isPublic: this.isPublic,
            createdAt: this.createdAt.toISOString(),
            attachedAgentPodName: this.attachedAgentPodName ?? null,
            attachedAgentSpecId: this.attachedAgentSpecId ?? null,
            attachedAgentGivenName: this.attachedAgentGivenName ?? null,
            hasAgent: this.hasAgent,
        };
    }
    /** Get raw space data as received from the API. */
    rawData() {
        this._checkDeleted();
        return this._data;
    }
    /** String representation of the project. */
    toString() {
        this._checkDeleted();
        return `Project(${this._data.uid}, ${this._data.name_t})`;
    }
    _checkDeleted() {
        if (this._deleted) {
            throw new Error(`Project ${this._data.uid} has been deleted and no longer exists`);
        }
    }
}
