import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { PhoneEntity } from './phone.entity';
import { PhoneAvatarEntity } from './phone-avatar.entity';

@Entity('phone_contacts')
export class PhoneContactEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() phone_id: number;
    @Column({ type: 'varchar', length: 32 }) name: string;
    @Column({ type: 'varchar', length: 32 }) number: string;

    @ManyToOne(() => PhoneEntity, (phone) => phone.contacts)
    @JoinColumn({ name: 'phone_id' })
    phone: PhoneEntity;

    @OneToOne(() => PhoneAvatarEntity)
    @JoinColumn({
        name: 'number',
        referencedColumnName: 'number',
    })
    avatar?: PhoneAvatarEntity;
}
