import { CreateDateColumn, Entity, Index, Column, RelationId, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm' import { ObjectType, Field, ID } from 'type-graphql' import { Domain, ScalarObject } from '@things-factory/shell' import { TwinSpace } from './twin-space.js' /* * TwinArea — 공간의 **논리적 구역(계층)**. 표현 무관(ISA-95 building→floor→zone). * area 단일화(space #2): deprecated `TwinSpace.content.areas`(blob) 를 정규화한 영구 자리. * 표현별 폴리곤(`TwinSpaceArea`)은 이 논리 구역을 `areaId` 로 참조한다(P2에서 binding.groupId→areaId 전환). * 안전 순서: P1=신설+인제스트 dual-write(content.areas 병행 유지) → P2 소비처 전환 → P3 blob 제거. */ @Entity() @Index('ix_twin_area_0', (e: TwinArea) => [e.domain, e.space, e.areaId], { unique: true }) @ObjectType({ description: 'A logical (representation-agnostic) area in a space hierarchy (building/floor/zone). Polygons reference it by areaId.' }) export class TwinArea { @PrimaryGeneratedColumn('uuid') @Field(type => ID) readonly id: string @ManyToOne(type => Domain) @Field(type => Domain, { nullable: true, description: 'Owning tenant domain.' }) domain?: Domain @RelationId((e: TwinArea) => e.domain) domainId?: string @ManyToOne(type => TwinSpace) @Field(type => TwinSpace, { nullable: true, description: 'Owning space.' }) space?: TwinSpace @RelationId((e: TwinArea) => e.space) spaceRowId?: string @Column() @Field({ description: 'Stable logical area id (unique within a space). Polygons reference this via areaId.' }) areaId: string @Column({ nullable: true }) @Field({ nullable: true, description: 'Area name.' }) name?: string @Column({ nullable: true }) @Field({ nullable: true, description: 'Region type (building/floor/zone/yard/dock…).' }) type?: string @Column({ nullable: true }) @Field({ nullable: true, description: 'Parent logical area id (hierarchy). Root areas have none.' }) parentId?: string @Column({ type: 'simple-json', nullable: true }) @Field(type => ScalarObject, { nullable: true, description: 'Layout footprint hint { x, y, w, h } in design coords (representation-agnostic).' }) layout?: any @CreateDateColumn() @Field({ nullable: true }) createdAt?: Date @UpdateDateColumn() @Field({ nullable: true }) updatedAt?: Date }