import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { ItemTypeEntity } from './item-type.entity';
import { PropertyEntity } from './property.entity';

@Entity('property_store_stocks')
export class PropertyStoreStockEntity {
    @PrimaryGeneratedColumn() id: number;
    @Column() property_id: number;
    @Column() item_type_id: number;
    @Column() price: number;
    @Column() discount: number;
    @Column({ type: 'varchar', length: 64, nullable: true }) custom_name: string | null;

    @ManyToOne(() => ItemTypeEntity, (type) => type.propertyStoreStock, {})
    @JoinColumn({ name: 'item_type_id' })
    itemType: ItemTypeEntity;

    @ManyToOne(() => PropertyEntity, (type) => type.itemStock)
    @JoinColumn({ name: 'property_id' })
    property: PropertyEntity;

    getName(): string {
        return this.custom_name ?? this.itemType.name;
    }
}
