import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
  Index,
} from 'typeorm';
import { Corp } from './corp.entity';

export type DomainRole = 'canonical' | 'alias' | 'seo_bait' | 'preview';

/**
 * Domain — hostname registered against a corp. Used to dimension every event
 * with corp_id + domain_id derived from the request Origin/Referer/Host.
 */
@Entity('domains')
@Index(['corpId'])
export class Domain {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: 'smallint', name: 'corp_id' })
  corpId!: number;

  @ManyToOne(() => Corp)
  @JoinColumn({ name: 'corp_id' })
  corp!: Corp;

  @Column({ type: 'varchar', length: 255, unique: true })
  hostname!: string;

  @Column({ type: 'varchar', length: 16 })
  role!: DomainRole;

  @CreateDateColumn({ type: 'timestamptz', name: 'created_at' })
  createdAt!: Date;
}
