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

@Entity('sessions')
export class SessionEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column({ type: 'int' }) account_id: number;
    @Column({ type: 'int', nullable: true }) character_id: number;
    @Column({ type: 'int', default: 0 }) play_time: number;
    @Column({ type: 'varchar', length: 16 }) ip: string;
    @Column({ type: 'int', unsigned: true }) ip_int32: number;
    @Column({ type: 'int' }) ip_int24: number;
    @Column({ type: 'int' }) ip_int16: number;
    @Column({ type: 'varchar', length: 128 }) serial: string;
    @Column({ type: 'varchar', length: 16 }) socialclub_id: string;
    @Column({ type: 'varchar', length: 16 }) socialclub_name: string;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) login: Date;
    @Column({ type: 'datetime', nullable: true }) logout: string;

    @Column({ type: 'int', default: 0 }) idle_time: number;

    @Column({ type: 'int', default: 0 }) idle_time_aduty: number;
    @Column({ type: 'int', default: 0 }) idle_time_tduty: number;
    @Column({ type: 'int', default: 0 }) idle_time_pdduty: number;
    @Column({ type: 'int', default: 0 }) idle_time_specialduty: number;

    @Column({ type: 'int', default: 0 }) aduty_time: number;
    @Column({ type: 'int', default: 0 }) tduty_time: number;
    @Column({ type: 'int', default: 0 }) quiet_time: number;

    @Column({ type: 'int', default: 0 }) pdduty_time: number;
    @Column({ type: 'int', default: 0 }) specialduty_time: number;

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