import { IsOptional, IsString } from 'class-validator';
import { UserGroup } from '../../entities/UserGroup';

/**
 * This classed is used to create a new UserGroup entity from a json body (post request).
 */
export class CreateUserGroup {
    /**
     * The new group's name.
     */
    @IsString()
    name: string;

    /**
     * The new group's description.
     * Optinal.
     */
    @IsOptional()
    @IsString()
    description?: string;

    /**
     * Creates a new UserGroup entity from this.
     */
    public async toEntity(): Promise<UserGroup> {
        let newUserGroup: UserGroup = new UserGroup();

        newUserGroup.name = this.name;
        newUserGroup.description = this.description;

        return newUserGroup;
    }
}