import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm'; import { BookingEntity } from './booking.entity'; import { BusinessAttributeValueEntity } from './business-attribute-value.entity'; import { BusinessAvailabilitySlotEntity } from './business-availability-slot.entity'; import { BusinessCategoryEntity } from './business-category.entity'; import { BusinessImageEntity } from './business-image.entity'; import { BusinessServiceClassEntity } from './business-service-class.entity'; import { BusinessServiceEntity } from './business-service.entity'; import { UserEntity } from './user.entity'; @Entity('businesses') export class BusinessEntity { @PrimaryGeneratedColumn('uuid') id!: string; @Column({ length: 150 }) title!: string; @Column({ unique: true, length: 120 }) slug!: string; @Column({ type: 'varchar', nullable: true, length: 150 }) subtitle!: string | null; @Column({ type: 'varchar', nullable: true, length: 500 }) description!: string | null; @Column({ type: 'varchar', nullable: true, length: 20 }) contactPhone!: string | null; @Column({ type: 'varchar', nullable: true, length: 500 }) address!: string | null; @Column({ type: 'double precision', nullable: true }) latitude!: number | null; @Column({ type: 'double precision', nullable: true }) longitude!: number | null; @Column({ default: true }) isActive!: boolean; @Column({ default: false }) serviceClassesEnabled!: boolean; @Column({ type: 'int', default: 1 }) concurrentCapacity!: number; @Column({ type: 'int', default: 30 }) slotStepMinutes!: number; /** When true, new bookings skip manual owner approval and go straight to payment. */ @Column({ default: false }) autoApproveBookings!: boolean; /** When true, customers can leave an optional gratuity after rating a completed booking. */ @Column({ default: false }) tipsEnabled!: boolean; @ManyToOne(() => BusinessCategoryEntity, (category) => category.businesses, { onDelete: 'RESTRICT', }) @JoinColumn({ name: 'categoryId' }) category!: BusinessCategoryEntity; @Column('uuid') categoryId!: string; @ManyToOne(() => UserEntity, (user) => user.ownedBusinesses, { nullable: true, onDelete: 'SET NULL', }) @JoinColumn({ name: 'ownerId' }) owner!: UserEntity | null; @Column({ type: 'uuid', nullable: true }) ownerId!: string | null; @OneToMany(() => BusinessImageEntity, (image) => image.business, { cascade: true, }) images!: BusinessImageEntity[]; @OneToMany(() => BusinessServiceEntity, (service) => service.business) services!: BusinessServiceEntity[]; @OneToMany(() => BusinessServiceClassEntity, (serviceClass) => serviceClass.business) serviceClasses!: BusinessServiceClassEntity[]; @OneToMany(() => BusinessAttributeValueEntity, (attr) => attr.business) attributes!: BusinessAttributeValueEntity[]; @OneToMany(() => BookingEntity, (booking) => booking.business) bookings!: BookingEntity[]; @OneToMany(() => BusinessAvailabilitySlotEntity, (slot) => slot.business, { cascade: true, }) availabilitySlots!: BusinessAvailabilitySlotEntity[]; @CreateDateColumn() createdAt!: Date; @UpdateDateColumn() updatedAt!: Date; }