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

export type SyncPlatform = 'dingtalk_students' | 'dingtalk_attendance' | 'wecom' | 'jinshuju';
export type SyncType = 'full' | 'incremental';
export type SyncStatus = 'running' | 'success' | 'partial' | 'failed';

@Entity('sync_logs')
export class SyncLog {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 20 })
  platform: SyncPlatform;

  @Column({ name: 'sync_type', type: 'varchar', length: 20 })
  syncType: SyncType;

  @Column({ type: 'varchar', length: 20 })
  status: SyncStatus;

  @Column({ name: 'records_count', type: 'integer', default: 0 })
  recordsCount: number;

  @Column({ name: 'error_message', type: 'text', nullable: true })
  errorMessage: string | null;

  @Column({ name: 'started_at', type: 'datetime', nullable: true })
  startedAt: Date | null;

  @Column({ name: 'finished_at', type: 'datetime', nullable: true })
  finishedAt: Date | null;

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