import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { PhoneConversationMemberEntity } from './phone-conversation-member.entity';

@Entity('phone_conversations')
export class PhoneConversationEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 32 }) name: string;
    @Column() member_count: number;
    @Column() last_message_id: number;
    @Column({ type: 'datetime' }) last_message_time: Date;
    @Column({ type: 'varchar', length: 16 }) last_message_type: string | null;
    @Column({ type: 'varchar', length: 512 }) last_message_content: string;
    @Column({ type: 'tinyint', width: 1, nullable: true }) last_message_delivered: boolean | null;
    @Column({ type: 'tinyint', width: 1, nullable: true }) last_message_read: boolean | null;
    @Column({ type: 'varchar', length: 32 }) last_message_phone_number: string;
    @Column({ nullable: true }) owner_membership_id: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) created: Date;

    @OneToMany(() => PhoneConversationMemberEntity, (member) => member.conversation)
    members: PhoneConversationMemberEntity[];

    member_numbers: string[];
}
