Custom user roles

To add a role see:
https://codex.wordpress.org/Function_Reference/add_role

To add capabilities see:
click add_cap link on the bottom

A list of all caps see:
https://codex.wordpress.org/Roles_and_Capabilities

For all the roles you can also use them for different post types.

if post type is “books”
edit_pages -> edit_books.

N.B.: This setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this on theme/plugin activation