export type TemplateType = 'portrait' | 'landscape'
export type TemplateSemester = 'first' | 'second'

export type TemplatePlaceholder = {
  name: string
  kind: 'text' | 'image'
}

export type TemplateFieldMapping = Record<string, string>

export type TemplateItem = {
  id: string
  name: string
  grade: string
  semester: TemplateSemester
  type: TemplateType
  originalFileName: string
  filePath: string
  fileExtension: string
  placeholders: TemplatePlaceholder[]
  fieldMappings: TemplateFieldMapping
  createdAt: string
  updatedAt: string
}

export type TemplateInput = {
  id?: string
  name: string
  grade: string
  semester: TemplateSemester
  type: TemplateType
  sourceFilePath: string
  fieldMappings?: TemplateFieldMapping
}

export type LoadTemplatesResponse =
  | {
      ok: true
      templates: TemplateItem[]
    }
  | {
      ok: false
      message: string
    }

export type SelectTemplateFileResponse =
  | {
      ok: true
      filePath: string
      fileName: string
    }
  | {
      ok: false
      canceled?: boolean
      message: string
    }

export type SaveTemplateResponse =
  | {
      ok: true
      template: TemplateItem
    }
  | {
      ok: false
      message: string
    }

export type ParseTemplatePlaceholdersResponse =
  | {
      ok: true
      placeholders: TemplatePlaceholder[]
    }
  | {
      ok: false
      message: string
    }

export type OpenTemplateResponse =
  | {
      ok: true
    }
  | {
      ok: false
      message: string
    }

export type DeleteTemplateResponse =
  | {
      ok: true
    }
  | {
      ok: false
      message: string
    }
