import { ArrayType, Entity, EntityRepositoryType, PrimaryKey, Property } from '@mikro-orm/core';
import { v4 } from 'uuid';

import { PostRepository } from '../repositories/post.repository';

@Entity({ repository: () => PostRepository, tableName: '3rapp_posts' })
export class PostEntity {
    [EntityRepositoryType]?: PostRepository;

    @PrimaryKey({ type: 'uuid' })
    id = v4();

    @Property({ index: true })
    title!: string;

    @Property({ type: 'text', lazy: true })
    body!: string;

    @Property({ type: ArrayType, nullable: true })
    keywords?: string[];

    @Property()
    createdAt = new Date();

    @Property({ onUpdate: () => new Date() })
    updatedAt = new Date();
}
