import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CharacterEntity } from './character.entity';
import { PrisonSentenceEntity } from './prison-sentences.entity';

@Entity('segregations')
export class SegregationEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) character_id: number;
    @Column({ type: 'int' }) sentence_id: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP()' }) segregated: Date;
    @Column({ type: 'int' }) segregated_by: number;
    /** @deprecated Use `segregated_for` which is in minutes */
    @Column({ type: 'datetime' }) segregated_until: Date;
    @Column({ type: 'int' }) segregated_for: number;
    @Column({ type: 'text', nullable: true, default: null }) reason: string | null;
    @Column({ type: 'datetime', default: null }) released: Date | null;
    @Column({ type: 'datetime', nullable: true, default: null }) released_by: number | null;
    @Column({ type: 'varchar', length: 256, nullable: true, default: null }) release_reason: string;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'character_id',
    })
    prisoner: CharacterEntity;

    @ManyToOne(() => PrisonSentenceEntity)
    @JoinColumn({
        name: 'sentence_id',
    })
    sentence: PrisonSentenceEntity;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'segregated_by',
    })
    segregatedBy: CharacterEntity;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({
        name: 'released_by',
    })
    releasedBy: CharacterEntity;
}
