import { GroupKind } from '../kinds.js';
import { nanoid } from '../../nanoid.js';
export class Group {
    kind = GroupKind;
    key = '';
    name = '';
    description;
    owner = '';
    icon;
    color;
    oid = '';
    users = [];
    createdAt = 0;
    updatedAt = 0;
    deleteInfo;
    static createSchema(input = {}) {
        const { key = nanoid() } = input;
        const result = {
            kind: GroupKind,
            key,
            name: input.name || 'Unnamed group',
            oid: input.oid || '',
            owner: input.owner || '',
            users: input.users || [],
            createdAt: input.createdAt || Date.now(),
            updatedAt: input.updatedAt || Date.now(),
        };
        if (input.description) {
            result.description = input.description;
        }
        if (input.icon) {
            result.icon = input.icon;
        }
        if (input.color) {
            result.color = input.color;
        }
        if (input.deleteInfo) {
            result.deleteInfo = input.deleteInfo;
        }
        return result;
    }
    static fromName(name, oid) {
        return new Group({ name, oid });
    }
    constructor(state) {
        const init = Group.createSchema(state);
        this.key = init.key;
        this.name = init.name;
        this.description = init.description;
        this.owner = init.owner;
        this.icon = init.icon;
        this.color = init.color;
        this.oid = init.oid;
        this.users = init.users;
        this.createdAt = init.createdAt;
        this.updatedAt = init.updatedAt;
        this.deleteInfo = init.deleteInfo;
    }
    toJSON() {
        const result = {
            kind: this.kind,
            key: GroupKind,
            name: this.name,
            oid: this.oid,
            owner: this.owner,
            users: [...this.users],
            createdAt: this.createdAt,
            updatedAt: this.updatedAt,
        };
        if (this.description) {
            result.description = this.description;
        }
        if (this.icon) {
            result.icon = this.icon;
        }
        if (this.color) {
            result.color = this.color;
        }
        if (this.deleteInfo) {
            result.deleteInfo = { ...this.deleteInfo };
        }
        return result;
    }
}
//# sourceMappingURL=Group.js.map