import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from 'typeorm';
import { PersonType } from './fiscal-regime.entity.js';

@Entity({ schema: 'fiscal', name: 'cfdi_uses' })
@Index('idx_cfdi_uses_code', ['code'], { unique: true })
@Index('idx_cfdi_uses_applies', ['appliesTo'])
export class CfdiUse {
  @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: 'simple-array', nullable: true, name: 'allowed_regimes' })
  allowedRegimes: 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;
}
