import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from 'typeorm';

export enum PersonType {
  NATURAL = 'natural',  // Persona fisica
  LEGAL = 'legal',      // Persona moral
  BOTH = 'both',
}

@Entity({ schema: 'fiscal', name: 'fiscal_regimes' })
@Index('idx_fiscal_regimes_code', ['code'], { unique: true })
@Index('idx_fiscal_regimes_applies', ['appliesTo'])
export class FiscalRegime {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'varchar', length: 10, nullable: false, unique: true })
  code: string;

  @Column({ type: 'varchar', length: 255, nullable: false })
  name: string;

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

  @Column({
    type: 'enum',
    enum: PersonType,
    nullable: false,
    default: PersonType.BOTH,
    name: 'applies_to',
  })
  appliesTo: PersonType;

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

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

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