/**
 * ProfileModule Entity
 * Module-level access control per profile
 * Compatible with erp-core profile-module.entity
 *
 * @module Profiles
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  Unique,
  Index,
} from 'typeorm';
import { UserProfile } from './user-profile.entity';

@Entity({ name: 'profile_modules', schema: 'auth' })
@Unique(['profileId', 'moduleCode'])
export class ProfileModule {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'profile_id', type: 'uuid' })
  profileId: string;

  @Column({ name: 'module_code', type: 'varchar', length: 50 })
  moduleCode: string;

  @Column({ name: 'access_level', type: 'varchar', length: 20, default: 'read' })
  accessLevel: 'read' | 'write' | 'admin';

  @Column({ name: 'can_export', type: 'boolean', default: false })
  canExport: boolean;

  @Column({ name: 'can_print', type: 'boolean', default: true })
  canPrint: boolean;

  @ManyToOne(() => UserProfile, (profile) => profile.modules, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'profile_id' })
  profile: UserProfile;
}
