import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, Check } from 'typeorm';
import { License } from './license.entity';
import { WipeProfile } from './wipe-profile.entity';

@Entity('wipe_schedules')
@Check(`"wipe_type" IN ('map', 'blueprint', 'full')`)
export class WipeSchedule {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  license_id: string;

  @Column({ type: 'uuid' })
  wipe_profile_id: string;

  @Column({ type: 'varchar', length: 100 })
  schedule_name: string;

  @Column({ type: 'varchar', length: 20 })
  wipe_type: string;

  @Column({ type: 'varchar', length: 100 })
  cron_expression: string;

  @Column({ type: 'varchar', length: 50, default: 'America/New_York' })
  timezone: string;

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

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

  @Column({ type: 'timestamptz', nullable: true })
  next_scheduled_run: Date | null;

  @Column({ type: 'timestamptz', default: () => 'NOW()' })
  created_at: Date;

  @ManyToOne(() => License, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'license_id' })
  license: License;

  @ManyToOne(() => WipeProfile, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'wipe_profile_id' })
  wipe_profile: WipeProfile;
}
