const { number, object, string } = require('yup');

const RssModel = require('../RssModel');
const RELATIONSHIP_SOURCE = require('../../constant/relationship/source.constant');

class Floor extends RssModel {
  constructor(payload = {}) {
    super(payload);
  }

  // eslint-disable-next-line class-methods-use-this
  schema() {
    return object().shape({
      id: string().required(),
      floorKey: string().required(),
      buildingId: string().required(),
      buildingKey: string().required(),
      name: string().max(128).trim().required().label('Name'),
      code: string().max(32).trim().nullable().default(null).label('Code'),
      size: number()
        .transform((value) => value || null)
        .nullable()
        .min(0, 'Size must be a positive number')
        .max(99999999999)
        .default(null)
        .label('Size'),
      groundPlane: number()
        .nullable()
        .transform((value) => (Number.isInteger(value) ? parseInt(value, 10) : null))
        .default(1)
        .max(99999999999)
        .label('Ground Plane'),
      source: string()
        .oneOf(Object.keys(RELATIONSHIP_SOURCE))
        .default(RELATIONSHIP_SOURCE.RSS)
        .required()
        .label('Source'),
    });
  }
}

module.exports = Floor;
