import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  Index,
  OneToMany,
} from 'typeorm';
import { TenantAwareEntity } from '../../../shared/entities/tenant-aware.entity';
import { Brand } from './brand.entity';

export enum ClientType {
  COMPANY = 'company',
  INDIVIDUAL = 'individual',
}

@Entity('clients', { schema: 'crm' })
@Index(['tenant_id', 'slug'], { unique: true })
export class Client extends TenantAwareEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ length: 255 })
  name: string;

  @Column({ length: 100 })
  slug: string;

  @Column({
    type: 'enum',
    enum: ClientType,
    default: ClientType.COMPANY,
  })
  type: ClientType;

  @Column({ length: 100, nullable: true })
  industry: string | null;

  @Column({ length: 500, nullable: true })
  website: string | null;

  @Column({ length: 500, nullable: true })
  logo_url: string | null;

  @Column({ length: 200, nullable: true })
  contact_name: string | null;

  @Column({ length: 255, nullable: true })
  contact_email: string | null;

  @Column({ length: 50, nullable: true })
  contact_phone: string | null;

  @Column({ type: 'text', nullable: true })
  notes: string | null;

  @Column({ default: true })
  is_active: boolean;

  @Column({ type: 'jsonb', nullable: true })
  metadata: Record<string, any> | null;

  @OneToMany(() => Brand, (brand) => brand.client)
  brands: Brand[];
}
