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

export enum TaxNature {
  TAX = 'tax',
  WITHHOLDING = 'withholding',
  BOTH = 'both',
}

@Entity({ schema: 'fiscal', name: 'tax_categories' })
@Index('idx_tax_categories_code', ['code'], { unique: true })
@Index('idx_tax_categories_sat', ['satCode'])
export class TaxCategory {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

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

  @Column({
    type: 'enum',
    enum: TaxNature,
    nullable: false,
    default: TaxNature.TAX,
    name: 'tax_nature',
  })
  taxNature: TaxNature;

  @Column({ type: 'varchar', length: 10, nullable: true, name: 'sat_code' })
  satCode: string | null;

  @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;
}
