{"size": 2416, "ext": "js", "max_stars_repo_path": "migrations/1638697337_createVideoIndexModel.js", "max_stars_repo_name": "bfabio/innovazione.gov.it-site", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "migrations/1638697337_createVideoIndexModel.js", "max_issues_repo_name": "bfabio/innovazione.gov.it-site", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "migrations/1638697337_createVideoIndexModel.js", "max_forks_repo_name": "bfabio/innovazione.gov.it-site", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.4838709677, "max_line_length": 75, "alphanum_fraction": 0.5335264901}
'use strict';

module.exports = async (client) => {

  const videoIndexModel = await client.itemTypes.create({
    name: 'Indice Video',
    apiKey: 'videos_index',
    singleton: true,
  });

  const titleField = await client.fields.create(videoIndexModel.id, {
    label: 'Titolo',
    apiKey: 'title',
    fieldType: 'string',
    position: 1,
    validators: {
      required: {},
      length: {
        max: 120,
      }
    },
    appearance: {
      editor: 'single_line',
      parameters: {
        heading: true,
      },
      addons: [],
    },
  });

  const videoModel = await client.itemType.find('video');

  const featuredField = await client.fields.create(videoIndexModel.id, {
    label: 'Video in evidenza',
    apiKey: 'featured_videos',
    fieldType: 'links',
    position: 2,
    validators: {
      size: {
        max: 3
      },
      itemsItemType: {
        item_types: [
          videoModel.id
        ]
      }
    },
    appearance: {
      editor: 'links_embed',
      parameters: {},
      addons: [],
    },
  });

  const menuLabelField = await client.fields.create(videoIndexModel.id, {
    label: 'Menu label',
    apiKey: 'menu_label',
    fieldType: 'string',
    position: 3,
    validators: {
      required: {},
      length: {
        max: 24,
      }
    },
    appearance: {
      editor: 'single_line',
      parameters: {
        heading: false,
      },
      addons: [],
    },
  });

  const slugField = await client.fields.create(videoIndexModel.id, {
    label: 'Slug',
    apiKey: 'slug',
    fieldType: 'slug',
    position: 4,
    validators: {
      slugTitleField: {
        titleFieldId: menuLabelField.id
      },
      required: {},
      unique: {},
      slugFormat: {
        predefinedPattern: 'webpage_slug'
      }
    },
    appearance: {
      editor: 'slug',
      parameters: {},
      addons: [],
    },
  });

  const seoMetatagsField = await client.fields.create(videoIndexModel.id, {
    label: 'SEO',
    apiKey: 'seo',
    fieldType: 'seo',
    position: 5,
    validators: {
      titleLength: {
        max: 60,
      },
      descriptionLength: {
        max: 160,
      },
    },
    appearance: {
      editor: 'seo',
      parameters: {},
      addons: [],
    },
  });

  const videoIndexContent = await client.items.create({
    itemType: videoIndexModel.id,
    title: "Video",
    menuLabel: "video",
    slug: "video"
  });
}
