import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Partner } from './partner.entity';

/**
 * PartnerContact Entity
 *
 * Synchronized with DDL: database/ddl/16-partners.sql
 * Table: partners.partner_contacts
 *
 * Represents individual contact persons of a partner.
 */
@Entity({ name: 'partner_contacts', schema: 'partners' })
export class PartnerContact {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index('idx_partner_contacts_partner')
  @Column({ name: 'partner_id', type: 'uuid' })
  partnerId: string;

  @ManyToOne(() => Partner, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'partner_id' })
  partner: Partner;

  // Datos personales
  @Column({ type: 'varchar', length: 200 })
  name: string;

  @Column({ name: 'job_title', type: 'varchar', length: 100, nullable: true })
  jobTitle: string | null;

  @Column({ type: 'varchar', length: 100, nullable: true })
  department: string | null;

  // Contacto
  @Index('idx_partner_contacts_email')
  @Column({ type: 'varchar', length: 255, nullable: true })
  email: string | null;

  @Column({ type: 'varchar', length: 30, nullable: true })
  phone: string | null;

  @Column({ type: 'varchar', length: 30, nullable: true })
  mobile: string | null;

  // Rol
  @Index('idx_partner_contacts_type')
  @Column({ name: 'contact_type', type: 'varchar', length: 20, default: 'general' })
  contactType: 'general' | 'billing' | 'purchasing' | 'sales' | 'technical';

  @Column({ name: 'is_primary', type: 'boolean', default: false })
  isPrimary: boolean;

  // Estado
  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

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

  // Metadata
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;

  @DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz', nullable: true })
  deletedAt: Date | null;
}
