import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  Index,
  ManyToOne,
  JoinColumn,
  OneToMany,
} from 'typeorm';
import { TenantAwareEntity } from '../../../shared/entities/tenant-aware.entity';
import { Client } from './client.entity';
import { Product } from './product.entity';

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

  @Column('uuid')
  client_id: string;

  @ManyToOne(() => Client, (client) => client.brands, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'client_id' })
  client: Client;

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

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

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

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

  @Column({ length: 7, nullable: true })
  primary_color: string | null;

  @Column({ length: 7, nullable: true })
  secondary_color: string | null;

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

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

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

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

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

  @OneToMany(() => Product, (product) => product.brand)
  products: Product[];
}
