import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { MemberAccount } from './MemberAccount';
import { MemberCashOut } from './MemberCashOut';
import { MemberLabel } from './MemberLabel';
import { MemberSign } from './MemberSign';
import { MemberLevel } from './MemberLevel';
import { MemberAddress } from './MemberAddress';
import { MemberAccountLog } from './MemberAccountLog';

@Entity('member')
export class Member {
  @PrimaryGeneratedColumn({ name: 'member_id' })
  member_id: number;

  @Column({ name: 'member_no', type: 'varchar', length: 255, default: '' })
  member_no: string;

  @Column({ name: 'pid', type: 'int', default: 0 })
  pid: number;

  @Column({ name: 'site_id', type: 'int', default: 0 })
  site_id: number;

  @Column({ name: 'username', type: 'varchar', length: 255, default: '' })
  username: string;

  @Column({ name: 'mobile', type: 'varchar', length: 20, default: '' })
  mobile: string;

  @Column({ name: 'password', type: 'varchar', length: 255, default: '' })
  password: string;

  @Column({ name: 'nickname', type: 'varchar', length: 255, default: '' })
  nickname: string;

  @Column({ name: 'headimg', type: 'varchar', length: 1000, default: '' })
  headimg: string;

  @Column({ name: 'member_level', type: 'int', default: 0 })
  member_level: number;

  @Column({ name: 'member_label', type: 'varchar', length: 255, default: '' })
  member_label: string;

  @Column({ name: 'wx_openid', type: 'varchar', length: 255, default: '' })
  wx_openid: string;

  @Column({ name: 'weapp_openid', type: 'varchar', length: 255, default: '' })
  weapp_openid: string;

  @Column({ name: 'wx_unionid', type: 'varchar', length: 255, default: '' })
  wx_unionid: string;

  @Column({ name: 'ali_openid', type: 'varchar', length: 255, default: '' })
  ali_openid: string;

  @Column({ name: 'douyin_openid', type: 'varchar', length: 255, default: '' })
  douyin_openid: string;

  @Column({ name: 'register_channel', type: 'varchar', length: 255, default: 'H5' })
  register_channel: string;

  @Column({ name: 'register_type', type: 'varchar', length: 255, default: '' })
  register_type: string;

  @Column({ name: 'login_ip', type: 'varchar', length: 255, default: '' })
  login_ip: string;

  @Column({ name: 'login_type', type: 'varchar', length: 255, default: 'h5' })
  login_type: string;

  @Column({ name: 'login_channel', type: 'varchar', length: 255, default: '' })
  login_channel: string;

  @Column({ name: 'login_count', type: 'int', default: 0 })
  login_count: number;

  @Column({ name: 'login_time', type: 'int', default: 0 })
  login_time: number;

  @Column({ name: 'create_time', type: 'int', default: 0 })
  create_time: number;

  @Column({ name: 'last_visit_time', type: 'int', default: 0 })
  last_visit_time: number;

  @Column({ name: 'last_consum_time', type: 'int', default: 0 })
  last_consum_time: number;

  @Column({ name: 'sex', type: 'tinyint', default: 0 })
  sex: number;

  @Column({ name: 'status', type: 'tinyint', default: 1 })
  status: number;

  @Column({ name: 'birthday', type: 'varchar', length: 20, default: '' })
  birthday: string;

  @Column({ name: 'id_card', type: 'varchar', length: 30, default: '' })
  id_card: string;

  @Column({ name: 'point', type: 'int', default: 0 })
  point: number;

  @Column({ name: 'point_get', type: 'int', default: 0 })
  point_get: number;

  @Column({ name: 'balance', type: 'decimal', precision: 10, scale: 2, default: 0 })
  balance: number;

  @Column({ name: 'balance_get', type: 'decimal', precision: 10, scale: 2, default: 0 })
  balance_get: number;

  @Column({ name: 'money', type: 'decimal', precision: 10, scale: 2, default: 0 })
  money: number;

  @Column({ name: 'money_get', type: 'decimal', precision: 10, scale: 2, default: 0 })
  money_get: number;

  @Column({ name: 'money_cash_outing', type: 'decimal', precision: 10, scale: 2, default: 0 })
  money_cash_outing: number;

  @Column({ name: 'growth', type: 'int', default: 0 })
  growth: number;

  @Column({ name: 'growth_get', type: 'int', default: 0 })
  growth_get: number;

  @Column({ name: 'commission', type: 'decimal', precision: 10, scale: 2, default: 0 })
  commission: number;

  @Column({ name: 'commission_get', type: 'decimal', precision: 10, scale: 2, default: 0 })
  commission_get: number;

  @Column({ name: 'commission_cash_outing', type: 'decimal', precision: 10, scale: 2, default: 0 })
  commission_cash_outing: number;

  @Column({ name: 'is_member', type: 'tinyint', default: 0 })
  is_member: number;

  @Column({ name: 'member_time', type: 'int', default: 0 })
  member_time: number;

  @Column({ name: 'is_del', type: 'tinyint', default: 0 })
  is_del: number;

  @Column({ name: 'province_id', type: 'int', default: 0 })
  province_id: number;

  @Column({ name: 'city_id', type: 'int', default: 0 })
  city_id: number;

  @Column({ name: 'district_id', type: 'int', default: 0 })
  district_id: number;

  @Column({ name: 'address', type: 'varchar', length: 255, default: '' })
  address: string;

  @Column({ name: 'location', type: 'varchar', length: 255, default: '' })
  location: string;

  @Column({ name: 'remark', type: 'varchar', length: 300, default: '' })
  remark: string;

  @Column({ name: 'delete_time', type: 'int', default: 0 })
  delete_time: number;

  @Column({ name: 'update_time', type: 'int', default: 0 })
  update_time: number;

  // 关联关系
  @OneToMany(() => MemberAccount, account => account.member)
  accounts: MemberAccount[];

  @OneToMany(() => MemberCashOut, cashOut => cashOut.member)
  cashOuts: MemberCashOut[];

  @OneToMany(() => MemberLabel, label => label.member)
  labels: MemberLabel[];

  @OneToMany(() => MemberSign, sign => sign.member)
  signs: MemberSign[];

  @ManyToOne(() => MemberLevel, level => level.members)
  @JoinColumn({ name: 'member_level' })
  level: MemberLevel;

  @OneToMany(() => MemberAddress, address => address.member)
  addresses: MemberAddress[];

  @OneToMany(() => MemberAccountLog, accountLog => accountLog.member)
  accountLogs: MemberAccountLog[];
} 