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

@Entity('theme', { schema: DB_SCHEMA })
export class ThemeEntity {
  @PrimaryGeneratedColumn({ type: 'smallint', name: 'id' })
  id: number;

  @Column('smallint', { name: 'by_user' })
  by_user: number;

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

  @Column('varchar', { name: 'themeColor', length: 100 })
  themeColor: string;

  @Column('tinyint', { name: 'isBookmarked', width: 1, default: () => "'0'" })
  isBookmarked: boolean;

  @Column('tinyint', { name: 'isRecent', default: () => "'0'" })
  isRecent: number;

  @Column('timestamp', { name: 'createdOn' })
  createdOn: Date;

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

  @ManyToOne(() => UserEntity, (user) => user.theme)
  @JoinColumn({ name: 'by_user', referencedColumnName: 'id' })
  user: UserEntity;
}
