import { Column, Entity, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CharacterEntity } from './character.entity';

@Entity('graffiti')
export class GraffitiEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'varchar', length: 32 }) content: string;
    @Column({ type: 'varchar', length: 32 }) font: string;
    @Column({ type: 'varchar', length: 6 }) colour: string;
    @Column({ type: 'int' }) x: number;
    @Column({ type: 'int' }) y: number;
    @Column({ type: 'int' }) z: number;
    @Column({ type: 'int' }) rx: number;
    @Column({ type: 'int' }) ry: number;
    @Column({ type: 'int' }) rz: number;
    @Column({ type: 'int' }) sx: number;
    @Column({ type: 'int' }) sy: number;
    @Column({ type: 'int' }) sz: number;
    @Column({ type: 'int' }) opacity: number; // 1 / 0.75 / 0.5 / 0.25 / 0
    @Column({ type: 'datetime', nullable: true }) last_stage_change: Date | null;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) created: Date;
    @Column({ type: 'int', nullable: false }) creator_id: number;
    @Column({ type: 'datetime', nullable: true }) destroyed: Date;
    @Column({ type: 'int', nullable: true }) destroyer_id: number | null;
    @Column({ type: 'int', nullable: true }) parent: number | null;
    @Column({ type: 'int', nullable: true }) child: number | null;
    @Column({ type: 'int' }) dimension: number;

    @ManyToOne(() => CharacterEntity, (character) => character.graffitis)
    @JoinColumn({ name: 'creator_id' })
    character?: CharacterEntity;

    streamedPlayers: Set<number> = new Set();

    lastSpray?: {
        player: number;
        time: number;
    };

    object?: ObjectMp;

    fixedPosition: Vector3;
}
