/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

import {
    Column,
    CreateDateColumn,
    Entity,
    JoinColumn,
    ManyToOne,
    PrimaryGeneratedColumn,
    UpdateDateColumn
} from "typeorm";
import {AuthContact} from "../contact";
import {AuthUser} from "../user";

@Entity()
export class AuthContactData {
    @PrimaryGeneratedColumn("uuid")
    id: string;

    @Column({type: "varchar", length: 30})
    type: string;

    @Column({type: "boolean", default: false})
    encrypted: boolean;

    @Column({type: "json"})
    content: string | number | Record<string, any>;

    @Column({type: "varchar"})
    contact_id: string;

    @ManyToOne(() => AuthContact, {onDelete: "CASCADE"})
    @JoinColumn({name: 'contact_id'})
    contact: AuthContact;

    @Column({type: "int", unsigned: true})
    from_user_id: number;

    @ManyToOne(() => AuthUser, {onDelete: "CASCADE"})
    @JoinColumn({name: 'from_user_id'})
    from_user: AuthUser;

    @Column({type: "int", unsigned: true})
    to_user_id: number;

    @ManyToOne(() => AuthUser, {onDelete: "CASCADE"})
    @JoinColumn({name: 'to_user_id'})
    to_user: AuthUser;

    @CreateDateColumn()
    created_at: string;

    @UpdateDateColumn()
    updated_at: string;
}
