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

class Presigned_url_requestsDBApi extends GenericDBApi {
  static get MODEL() {
    return db.presigned_url_requests;
  }

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

  static get SEARCHABLE_FIELDS() {
    return ['requested_key', 'mime_type', 'status'];
  }

  static get RANGE_FIELDS() {
    return ['requested_size_mb', 'expires_at'];
  }

  static get ENUM_FIELDS() {
    return ['purpose', 'asset_type'];
  }

  static get CSV_FIELDS() {
    return [
      'id',
      'purpose',
      'asset_type',
      'requested_key',
      'mime_type',
      'status',
      'createdAt',
    ];
  }

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

  static get ASSOCIATIONS() {
    return [
      { field: 'project', setter: 'setProject', isArray: false },
      { field: 'user', setter: 'setUser', isArray: false },
    ];
  }

  static get FIND_BY_INCLUDES() {
    return [{ association: 'project' }, { association: 'user' }];
  }

  static get FIND_ALL_INCLUDES() {
    return [
      { model: db.projects, as: 'project', required: false },
      { model: db.users, as: 'user', required: false },
    ];
  }

  static get RELATION_FILTERS() {
    return [
      {
        filterKey: 'project',
        model: db.projects,
        as: 'project',
        searchField: 'name',
      },
      {
        filterKey: 'user',
        model: db.users,
        as: 'user',
        searchField: 'firstName',
      },
    ];
  }

  static getFieldMapping(data) {
    return {
      id: data.id || undefined,
      purpose: data.purpose || null,
      asset_type: data.asset_type || null,
      requested_key: data.requested_key || null,
      mime_type: data.mime_type || null,
      requested_size_mb: data.requested_size_mb || null,
      expires_at: data.expires_at || null,
      status: data.status || null,
    };
  }
}

module.exports = Presigned_url_requestsDBApi;
