const GenericDBApi = require('./base.api');
const db = require('../models');

class Asset_variantsDBApi extends GenericDBApi {
  static get MODEL() {
    return db.asset_variants;
  }

  static get TABLE_NAME() {
    return 'asset_variants';
  }

  static get SEARCHABLE_FIELDS() {
    return ['cdn_url'];
  }

  static get RANGE_FIELDS() {
    return ['width_px', 'height_px', 'size_mb'];
  }

  static get ENUM_FIELDS() {
    return ['variant_type'];
  }

  static get CSV_FIELDS() {
    return [
      'id',
      'variant_type',
      'cdn_url',
      'width_px',
      'height_px',
      'size_mb',
      'createdAt',
    ];
  }

  static get AUTOCOMPLETE_FIELD() {
    return 'variant_type';
  }

  static get ASSOCIATIONS() {
    return [{ field: 'asset', setter: 'setAsset', isArray: false }];
  }

  static get FIND_BY_INCLUDES() {
    return [{ association: 'asset' }];
  }

  static get FIND_ALL_INCLUDES() {
    return [
      {
        model: db.assets,
        as: 'asset',
        required: false,
      },
    ];
  }

  static get RELATION_FILTERS() {
    return [
      {
        filterKey: 'asset',
        model: db.assets,
        as: 'asset',
        searchField: 'name',
      },
    ];
  }

  static getFieldMapping(data) {
    return {
      id: data.id || undefined,
      variant_type: data.variant_type || null,
      cdn_url: data.cdn_url || null,
      width_px: data.width_px || null,
      height_px: data.height_px || null,
      size_mb: data.size_mb || null,
    };
  }
}

module.exports = Asset_variantsDBApi;
