import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from 'typeorm';

@Entity({ schema: 'projects', name: 'project_stages' })
@Index('idx_project_stages_tenant', ['tenantId'])
@Index('idx_project_stages_project', ['projectId'])
@Index('idx_project_stages_sequence', ['sequence'])
export class ProjectStageEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
  tenantId: string;

  @Column({ type: 'uuid', nullable: true, name: 'project_id' })
  projectId: string | null;

  @Column({ type: 'varchar', length: 100, nullable: false })
  name: string;

  @Column({ type: 'int', default: 0, nullable: false })
  sequence: number;

  @Column({ type: 'boolean', default: false, nullable: false })
  fold: boolean;

  @Column({ type: 'boolean', default: false, nullable: false, name: 'is_closed' })
  isClosed: boolean;

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

  @UpdateDateColumn({
    name: 'updated_at',
    type: 'timestamptz',
    nullable: true,
  })
  updatedAt: Date | null;
}
