import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { File } from '@d8d/file-module';
import { AdvertisementType } from './advertisement-type.entity';

@Entity('ad')
export class Advertisement {
  @PrimaryGeneratedColumn({ unsigned: true })
  id!: number;

  @Column({
    name: 'title',
    type: 'varchar',
    length: 30,
    nullable: true,
    comment: '标题'
  })
  title!: string | null;

  @Column({
    name: 'type_id',
    type: 'int',
    nullable: true,
    unsigned: true,
    comment: '广告类型'
  })
  typeId!: number | null;

  @Column({
    name: 'code',
    type: 'varchar',
    length: 20,
    nullable: true,
    comment: '调用别名'
  })
  code!: string | null;

  @Column({
    name: 'url',
    type: 'varchar',
    length: 255,
    nullable: true,
    comment: 'url'
  })
  url!: string | null;

  @Column({
    name: 'image_file_id',
    type: 'int',
    unsigned: true,
    nullable: true,
    comment: '图片文件ID'
  })
  imageFileId!: number | null;

  @ManyToOne(() => File, { nullable: true })
  @JoinColumn({
    name: 'image_file_id',
    referencedColumnName: 'id'
  })
  imageFile!: File | null;

  @ManyToOne(() => AdvertisementType, { nullable: true })
  @JoinColumn({
    name: 'type_id',
    referencedColumnName: 'id'
  })
  advertisementType!: AdvertisementType | null;

  @Column({
    name: 'sort',
    type: 'int',
    default: 0,
    comment: '排序'
  })
  sort!: number;

  @CreateDateColumn({
    name: 'created_at',
    type: 'timestamp',
    comment: '创建时间'
  })
  createdAt!: Date;

  @UpdateDateColumn({
    name: 'updated_at',
    type: 'timestamp',
    comment: '更新时间'
  })
  updatedAt!: Date;

  @Column({
    name: 'created_by',
    type: 'int',
    unsigned: true,
    nullable: true,
    comment: '创建用户ID'
  })
  createdBy!: number | null;

  @Column({
    name: 'updated_by',
    type: 'int',
    unsigned: true,
    nullable: true,
    comment: '更新用户ID'
  })
  updatedBy!: number | null;

  @Column({
    name: 'status',
    type: 'int',
    unsigned: true,
    default: 0,
    comment: '状态'
  })
  status!: number;

  @Column({
    name: 'action_type',
    type: 'int',
    default: 1,
    comment: '跳转类型 0 不跳转 1webview 2小程序页面'
  })
  actionType!: number;
}