// src/entities/user.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, OneToOne, JoinColumn } from 'typeorm';
import { Address } from '../entity/Address';
import { Order } from '../entity/order';
// import { Review } from '../entity/';
import { Cart } from '../entity/cart';
import { Wishlist } from '../entity/wishlist';
import { Vendor } from '../entity/vendor';
import { Review } from './review';

export enum UserRole {
  CUSTOMER = 'customer',
  ADMIN = 'admin',
  VENDOR = 'vendor'
}

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  user_id?: number;

  @Column()
  name?: string;

  @Column({ unique: true })
  email?: string;

  @Column()
  password_hash?: string;

  @Column({ nullable: true })
  phone_number?: string;

  @Column({
    type: 'enum',
    enum: UserRole,
    default: UserRole.CUSTOMER
  })
  role?: UserRole;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  created_at?: Date;

  @Column({ nullable: true })
  gstin?: string;

  @Column({ default: false })
  is_business?: boolean;

  // Relations
  @OneToMany(() => Address, address => address.user)
  addresses?: Address[];

  @OneToMany(() => Order, order => order.user)
  orders?: Order[];

  @OneToMany(() => Review, review => review.user)
  reviews?: Review[];

  @OneToOne(() => Cart, cart => cart.user)
  cart?: Cart;

  @OneToMany(() => Wishlist, wishlist => wishlist.user)
  wishlists?: Wishlist[];

  @OneToOne(() => Vendor, vendor => vendor.user)
  vendor?: Vendor;
}