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

@Entity('favorite_menu', { schema: DB_SCHEMA })
export class FavoriteMenuEntity {
  @PrimaryGeneratedColumn({ type: 'mediumint', name: 'id' })
  id: number;

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

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

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

  @Column('varchar', { name: 'menu_name', length: 60 })
  menu_name: string;

  @Column('varchar', { name: 'menu_link', length: 255 })
  menu_link: string;

  @Column('tinyint', { name: 'active', width: 1, default: () => "'1'" })
  active: number;

  @Column('tinyint', { name: 'platform', width: 1, default: () => "'1'" })
  platform: number;

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

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

  @ManyToOne(() => UserEntity, (user) => user.favorite_menu, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn({ name: 'user_id' })
  user: UserEntity;
}
