import { Column, Entity, Index, JoinColumn, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { MazePayAccountEntity } from './maze-pay-account.entity';
import { CharacterEntity } from './character.entity';

@Entity('maze_pay_payments')
export class MazePayPaymentEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() maze_pay_account_id: number;
    @Column() counter_maze_pay_account_id: number;
    @Index()
    @Column()
    created_by_character_id: number;
    @Column() amount: number;
    @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) created: Date;
    @Column({ type: 'varchar', length: 36 }) bank_transaction_ref: string;
    @Column({ type: 'varchar', length: 64 }) note: string | null;

    @OneToOne(() => MazePayAccountEntity)
    @JoinColumn({ name: 'maze_pay_account_id', referencedColumnName: 'id' })
    mazePayAccount: MazePayAccountEntity;

    @OneToOne(() => MazePayAccountEntity)
    @JoinColumn({ name: 'counter_maze_pay_account_id', referencedColumnName: 'id' })
    counterMazePayAccount: MazePayAccountEntity;

    @ManyToOne(() => CharacterEntity)
    @JoinColumn({ name: 'created_by_character_id' })
    createdByCharacter?: CharacterEntity;
}
