import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { BankEntity } from './bank.entity';
import { CompanyEntity } from './company.entity';

@Entity('atms')
export class AtmEntity {
    static MAX_CASH = 100_000;

    @PrimaryGeneratedColumn() id: number;
    @Index()
    @Column()
    bank_id: number;
    @Column() posx: number;
    @Column() posy: number;
    @Column() posz: number;
    @Column() rotx: number;
    @Column() roty: number;
    @Column() rotz: number;
    @Column({ type: 'varchar', length: 20, default: null, nullable: true }) model: string | null;
    @Column('datetime') created: string;
    @Column() dimension: number;
    @Index()
    @Column({ type: 'int', nullable: true })
    operator_id: number | null;
    @Column() fee: number;

    operatedBy?: PlayerMpLoggedIn;
    object?: ObjectMp;

    @ManyToOne(() => BankEntity, (bank) => bank.accounts)
    @JoinColumn({ name: 'bank_id' })
    bank?: BankEntity;

    @ManyToOne(() => CompanyEntity)
    @JoinColumn({ name: 'operator_id' })
    operator?: CompanyEntity;

    availableCash = AtmEntity.MAX_CASH;

    position() {
        return new mp.Vector3(this.posx, this.posy, this.posz);
    }
}
