import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    UpdateDateColumn,
    ManyToOne,
    JoinColumn,
} from 'typeorm';
import { User } from '../../user/user.entity';
import { KnowledgeGroup } from '../../knowledge-group/knowledge-group.entity';
import { Tenant } from '../../tenant/tenant.entity';

export enum PodcastStatus {
    PENDING = 'pending',
    PROCESSING = 'processing',
    COMPLETED = 'completed',
    FAILED = 'failed',
}

@Entity('podcast_episodes')
export class PodcastEpisode {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Column()
    title: string;

    @Column('text', { nullable: true })
    briefing: string; // The instruction/prompt used

    @Column({ nullable: true })
    audioUrl: string;

    @Column('simple-json', { nullable: true })
    transcript: any; // The dialogue script

    @Column({
        type: 'simple-enum',
        enum: PodcastStatus,
        default: PodcastStatus.PENDING,
    })
    status: PodcastStatus;

    @Column({ name: 'user_id' })
    userId: string;

    @Column({ name: 'group_id', nullable: true })
    groupId: string;

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

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

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

    @ManyToOne(() => User)
    @JoinColumn({ name: 'user_id' })
    user: User;

    @ManyToOne(() => KnowledgeGroup)
    @JoinColumn({ name: 'group_id' })
    group: KnowledgeGroup;

    @ManyToOne(() => Tenant)
    @JoinColumn({ name: 'tenant_id' })
    tenant: Tenant;
}
