% This file is public domain. See the "Examples" chapter
% in the bib2gls user manual for a more detailed description
% of this file.

\documentclass[11pt,a4paper]{report}

\usepackage[T1]{fontenc}
\usepackage[colorlinks]{hyperref}
\usepackage[record,% using bib2gls
 nostyles,% don't load default styles
 postdot,% append a dot after descriptions
 stylemods={list},% load glossary-list.sty and fix styles
 style=altlistgroup]{glossaries-extra}

\GlsXtrLoadResources[
  src=no-interpret-preamble,
  interpret-preamble=false
]

\GlsXtrLoadResources[
  src={interpret-preamble,books,films},
  field-aliases={identifier=category,year=user1,cast=user2},
  bibtex-contributor-fields={user2},
  contributor-order={forenames},
  identical-sort-action={category},
  save-locations=false,
  selection=all
]

% requires datatool-base.sty v2.28+:
\renewcommand*{\DTLlistformatoxford}{,}
\renewcommand*{\DTLandname}{and}

\newcommand*{\bookfont}[1]{\emph{#1}}
\newcommand*{\filmfont}[1]{\textsf{\em #1}}

\glssetcategoryattribute{book}{textformat}{bookfont}
\glssetcategoryattribute{book}{glossnamefont}{bookfont}

\glssetcategoryattribute{film}{textformat}{filmfont}
\glssetcategoryattribute{film}{glossnamefont}{filmfont}

\newcommand*{\glsxtrpostnamebook}{%
 \ifglshasfield{user1}{\glscurrententrylabel}%
 {\space(published \glscurrentfieldvalue)}%
 {}%
}

\newcommand*{\glsxtrpostnamefilm}{%
 \ifglshasfield{user1}{\glscurrententrylabel}%
 {\space (released \glscurrentfieldvalue)}%
 {}%
}

\newcommand*{\glsxtrpostdescfilm}{%
 \ifglshasfield{user2}{\glscurrententrylabel}%
 {%
   \glsxtrrestorepostpunc % requires glossaries-extra v1.23+
   \ featuring \glscurrentfieldvalue
 }%
 {}%
}

\begin{document}
\printunsrtglossaries
\end{document}
