import FieldDTO from './field-dto.js'
import JobNotificationDTO from './job-notification-dto.js'
import JobRecordDTO from './job-record-dto.js'
/**
*
*/
class JobDTO {
/**
* @param {any} [json]
*/
constructor (json) {
if (!json) {
json = {}
}
this.json = json
this.notifications = json.notifications?.map(o => new JobNotificationDTO(o)) || undefined
this.records = json.records?.map(o => new JobRecordDTO(o))
}
/**
* @type {number}
*/
get concurrency () {
return this.json.concurrency
}
/**
* @type {number}
*/
get concurrencyDelay () {
return this.json.concurrencyDelay
}
/**
* @type {string}
*/
get cron () {
return this.json.cron
}
set cron (s) {
this.json.cron = s
}
/**
* @returns {number}
*/
get duration () {
return this.json.duration
}
/**
* @type {FieldDTO[]}
*/
get fields () {
return this.json.fields.map(o => new FieldDTO(o))
}
/**
* @type {string}
*/
get id () {
return this.json.id
}
/**
* @type {string}
*/
get name () {
return this.json.name
}
set name (v) {
this.json.name = v
}
/**
* @returns {boolean}
*/
get scheduled () {
return this.json.scheduled
}
set scheduled (b) {
this.json.scheduled = b
}
/**
* @returns {string}
*/
get webhookURL () {
return this.json.webhookURL
}
set webhookURL (s) {
this.json.webhookURL = s
}
/**
*
* @param {JobRecordDTO} record
* @returns {void}
*/
addRecord (record) {
this.json.records.push(record.json)
}
/**
* @returns {FieldDTO[]}
*/
expectedFields () {
return this.fields.filter(f => f.fieldType === 'EXPECTED')
}
/**
*
* @param {string} name
* @returns {FieldDTO | undefined}
*/
field (name) {
return this.fields.find(f => f.name === name)
}
/**
* @returns {boolean}
*/
usingClassifier () {
if (this.webhookURL && this.webhookURL.endsWith('classify')) {
return true
}
return false
}
/**
* @returns {FieldDTO[]}
*/
inputFields () {
return this.fields.filter(f => f.fieldType === 'INPUT')
}
}
export default JobDTO