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

export type JobLocation = 'Remote' | 'Hybrid' | 'On-site';

export type JobContentSection = {
  title: string;      // e.g. "Responsibilities", "Requirements", "About Us"
  content: string[];  // Array of bullet points or paragraphs
  order?: number;     // Optional ordering of sections
};

@Entity('jobs')
export class Job {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'title', type: 'varchar' })
  title: string;

  @Column({ name: 'department', type: 'varchar' })
  department: string;

  @Column({ name: 'location', type: 'json' })
  location: {
    type: JobLocation;
    region: string;
  };

  @Column({ name: 'description', type: 'text' })
  description: string;

  @Column({ name: 'content_sections', type: 'json', nullable: true })
  contentSections: JobContentSection[];

  @Column({ name: 'salary_range', type: 'json', nullable: true })
  salaryRange?: {
    min?: number;
    max?: number;
    currency?: string;
  };

  @Column({ name: 'slug', type: 'varchar', nullable: true })
  slug?: string;

  @Column({ name: 'posted_at', type: 'timestamp' })
  postedAt: Date;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

  @Column({ name: 'application_url', type: 'varchar', nullable: true })
  applicationUrl?: string;

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

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  updatedAt: Date;
}