58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
|
|
import type { UnifiAccount } from './classes.unifi-account.js';
|
||
|
|
import type { IUnifiSite } from './interfaces/index.js';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Represents a UniFi site from Site Manager
|
||
|
|
*/
|
||
|
|
export class UnifiSite implements IUnifiSite {
|
||
|
|
/** Reference to parent account */
|
||
|
|
private unifiAccount?: UnifiAccount;
|
||
|
|
|
||
|
|
// IUnifiSite properties
|
||
|
|
public siteId: string;
|
||
|
|
public name: string;
|
||
|
|
public description?: string;
|
||
|
|
public isDefault?: boolean;
|
||
|
|
public timezone?: string;
|
||
|
|
public meta?: {
|
||
|
|
type?: string;
|
||
|
|
address?: string;
|
||
|
|
};
|
||
|
|
public createdAt?: string;
|
||
|
|
public updatedAt?: string;
|
||
|
|
|
||
|
|
constructor() {
|
||
|
|
this.siteId = '';
|
||
|
|
this.name = '';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a site instance from API response object
|
||
|
|
*/
|
||
|
|
public static createFromApiObject(
|
||
|
|
apiObject: IUnifiSite,
|
||
|
|
unifiAccount?: UnifiAccount
|
||
|
|
): UnifiSite {
|
||
|
|
const site = new UnifiSite();
|
||
|
|
Object.assign(site, apiObject);
|
||
|
|
site.unifiAccount = unifiAccount;
|
||
|
|
return site;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the raw API object representation
|
||
|
|
*/
|
||
|
|
public toApiObject(): IUnifiSite {
|
||
|
|
return {
|
||
|
|
siteId: this.siteId,
|
||
|
|
name: this.name,
|
||
|
|
description: this.description,
|
||
|
|
isDefault: this.isDefault,
|
||
|
|
timezone: this.timezone,
|
||
|
|
meta: this.meta,
|
||
|
|
createdAt: this.createdAt,
|
||
|
|
updatedAt: this.updatedAt,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|