import { Entity, Property, ManyToOne, Index } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';

@Entity({ tableName: 'user_addresses' })
@Index({ properties: ['user'] })
export class UserAddress extends BaseEntity {
  @ManyToOne(() => User)
  user!: User;

  @Property()
  title!: string; // e.g., "Home", "Work", "Office"

  @Property()
  address!: string;

  @Property()
  city!: string;

  @Property({ nullable: true })
  province?: string;

  @Property({ nullable: true })
  postalCode?: string | null = null;

  @Property({ type: 'float' })
  latitude!: number;

  @Property({ type: 'float' })
  longitude!: number;

  @Property({ nullable: true })
  phone?: string; // Contact phone for this address

  @Property({ default: false })
  isDefault: boolean = false; // Whether this is the default address
}
