import { EntitySchema } from 'typeorm'

export type TemplateEntity = {
  id: string
  name: string
  grade: string
  semester: string
  type: string
  originalFileName: string
  filePath: string
  fileExtension: string
  placeholders: string
  fieldMappings: string
  createdAt: string
  updatedAt: string
}

export const TemplateEntitySchema = new EntitySchema<TemplateEntity>({
  name: 'TemplateEntity',
  tableName: 'templates',
  columns: {
    id: {
      type: String,
      primary: true
    },
    name: {
      type: String
    },
    grade: {
      type: String
    },
    semester: {
      type: String,
      default: 'first'
    },
    type: {
      type: String
    },
    originalFileName: {
      name: 'original_file_name',
      type: String
    },
    filePath: {
      name: 'file_path',
      type: String
    },
    fileExtension: {
      name: 'file_extension',
      type: String
    },
    placeholders: {
      type: String,
      default: '[]'
    },
    fieldMappings: {
      name: 'field_mappings',
      type: String,
      default: '{}'
    },
    createdAt: {
      name: 'created_at',
      type: String
    },
    updatedAt: {
      name: 'updated_at',
      type: String
    }
  },
  indices: [
    {
      name: 'idx_templates_name',
      columns: ['name']
    }
  ],
  relations: {}
})
