import type { CertificateTemplateConfig, IdPhotoConfig, IdPhotoCrop } from '@/lib/certificate-types'
import type { ImageSource } from '@/lib/certificate-browser'

export type PersistedImageSource = Omit<ImageSource, 'blob'>

export type PersistedGeneratedAsset = {
  fileName: string
}

export type PersistedClassStudent = {
  id: string
  name: string
  photo?: PersistedImageSource
  photoFileName?: string
  idPhoto?: PersistedImageSource
  idPhotoFileName?: string
  idPhotoCrop?: IdPhotoCrop
}

export type PersistedClassItem = {
  id: string
  name: string
  students: PersistedClassStudent[]
  idPhotoConfig?: IdPhotoConfig
  createdAt: string
}

export type PersistedTemplateItem = {
  id: string
  name: string
  image: PersistedImageSource
  config: CertificateTemplateConfig
  updatedAt: string
}

export type PersistedGeneratedCertificate = {
  id: string
  classId: string
  className: string
  studentId: string
  studentName: string
  photo: PersistedImageSource
  template: PersistedTemplateItem
  asset: PersistedGeneratedAsset
  jpgUrl?: string
  updatedAt: string
}

export type PersistedAppState = {
  templates: PersistedTemplateItem[]
  activeTemplateId: string
  classes: PersistedClassItem[]
  activeClassId: string
  certificates: PersistedGeneratedCertificate[]
}
