import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm'; import { ApiProperty } from '@nestjs/swagger'; import { BaseEntity } from './base.entity'; import { Establishment } from './establishment.entity'; import { User } from './user.entity'; @Entity({ name: 'listings', schema: 'commerce' }) export class Listing extends BaseEntity { @ApiProperty({ description: 'Property owner user ID' }) @Column({ name: 'owner_id' }) ownerId: string; @ApiProperty({ description: 'Associated establishment ID' }) @Column({ name: 'establishment_id', type: 'uuid', nullable: true }) establishmentId: string | null; @ApiProperty({ description: 'Listing type', example: 'hotel' }) @Column({ name: 'listing_type', length: 50 }) listingType: string; @ApiProperty({ description: 'Listing title', example: 'Luxury Beach Resort in Punta Cana' }) @Column({ length: 255 }) title: string; @ApiProperty({ description: 'Detailed description' }) @Column({ type: 'text' }) description: string; @ApiProperty({ description: 'Property location' }) @Column({ type: 'point', nullable: true }) coordinates: string | null; @ApiProperty({ description: 'Address' }) @Column({ type: 'text', nullable: true }) address: string | null; @ApiProperty({ description: 'Base price per night/hour/day' }) @Column({ name: 'base_price', type: 'decimal', precision: 10, scale: 2 }) basePrice: number; @ApiProperty({ description: 'Currency', example: 'USD' }) @Column({ length: 3, default: 'USD' }) currency: string; @ApiProperty({ description: 'Maximum capacity', example: 4 }) @Column({ type: 'integer', nullable: true }) capacity: number | null; @ApiProperty({ description: 'Amenities list' }) @Column({ type: 'text', array: true, nullable: true }) amenities: string[] | null; @ApiProperty({ description: 'Property images' }) @Column({ type: 'jsonb', nullable: true }) images: Record[] | null; @ApiProperty({ description: 'Property rules and policies' }) @Column({ type: 'jsonb', nullable: true }) policies: Record | null; @ApiProperty({ description: 'Check-in time', example: '15:00' }) @Column({ name: 'checkin_time', type: 'varchar', nullable: true }) checkinTime: string | null; @ApiProperty({ description: 'Check-out time', example: '11:00' }) @Column({ name: 'checkout_time', type: 'varchar', nullable: true }) checkoutTime: string | null; @ApiProperty({ description: 'Minimum stay nights', example: 2 }) @Column({ name: 'min_stay', type: 'integer', nullable: true }) minStay: number | null; @ApiProperty({ description: 'Maximum stay nights', example: 30 }) @Column({ name: 'max_stay', type: 'integer', nullable: true }) maxStay: number | null; @ApiProperty({ description: 'Channel distribution settings' }) @Column({ name: 'channel_settings', type: 'jsonb', nullable: true }) channelSettings: Record | null; @ApiProperty({ description: 'Listing status', example: 'published' }) @Column({ length: 20, default: 'draft' }) status: string; @ApiProperty({ description: 'Average rating', example: 4.5 }) @Column({ type: 'decimal', precision: 3, scale: 2, nullable: true }) rating: number | null; @ApiProperty({ description: 'Total reviews count' }) @Column({ name: 'reviews_count', default: 0 }) reviewsCount: number; @ApiProperty({ description: 'Booking count' }) @Column({ name: 'bookings_count', default: 0 }) bookingsCount: number; @ApiProperty({ description: 'Last updated' }) @Column({ name: 'last_updated', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' }) lastUpdated: Date; // Relations @ManyToOne(() => User) @JoinColumn({ name: 'owner_id' }) owner: User; @ManyToOne(() => Establishment) @JoinColumn({ name: 'establishment_id' }) establishment: Establishment; }