import { DB_SCHEMA } from 'src/utils';
import {
  Column,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { UserEntity } from './User.entity';

@Index('release_version', ['release_version'], { unique: true })
@Entity('release_notes', { schema: DB_SCHEMA })
export class ReleaseNotesEntity {
  @PrimaryGeneratedColumn({ type: 'int', name: 'release_id' })
  release_id: number;

  @Column('varchar', {
    name: 'release_version',
    nullable: true,
    unique: true,
    length: 8,
  })
  release_version: string | null;

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

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

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

  @Column('varchar', { name: 'release_date', length: 10 })
  release_date: string;

  @Column('timestamp', {
    name: 'release_datestr',
    default: () => 'CURRENT_TIMESTAMP',
  })
  release_datestr: Date;

  @Column('tinyint', { name: 'status', width: 1 })
  status: boolean;

  @Column('smallint', { name: 'by_user', nullable: true })
  by_user: number | null;

  @Column('timestamp', { name: 'created', default: () => 'CURRENT_TIMESTAMP' })
  created: Date;

  @Column('timestamp', { name: 'modified', default: () => 'CURRENT_TIMESTAMP' })
  modified: Date;

  @Column('varchar', { name: 'user_name', nullable: true, length: 25 })
  user_name: string | null;

  @ManyToOne(() => UserEntity, (user) => user.release_notes, { nullable: true })
  @JoinColumn({ name: 'by_user' })
  user: UserEntity;
}
